r2 ./license_1

aaa, analisi automatica del binario

[0x004005c5]> aaa
[x] Analyze all flags starting with sym. and entry0 (aa)
[x] Analyze function calls (aac)
[x] Analyze len bytes of instructions for references (aar)
[x] Check for objc references
[x] Check for vtables
[x] Type matching analysis for all functions (aaft)
[x] Propagate noreturn information
[x] Use -AA or aaaa to perform additional experimental analysis.

afl, list functions

[0x004005c5]> afl
0x004004d0    1 41           entry0
0x004004a0    1 6            sym.imp.__libc_start_main
0x00400500    4 41           sym.deregister_tm_clones
0x00400530    4 57           sym.register_tm_clones
0x00400570    3 28           entry.fini0
0x00400590    4 45   -> 42   entry.init0
0x004006b0    1 2            sym.__libc_csu_fini
0x004006b4    1 9            sym._fini
0x00400640    4 101          sym.__libc_csu_init
0x004005bd    6 119          main
0x00400450    3 26           sym._init
0x004004c0    1 6            loc.imp.__gmon_start
0x00400480    1 6            sym.imp.puts
0x00400490    1 6            sym.imp.printf
0x004004b0    1 6            sym.imp.strcmp

s sym.main

V , ti permette di visualizzare il binario in diversi modi, codice assembler, ascii, debug, byte colorati

[0x004005c5]> V

ti muovi tra le varie visualizzazione con p per adnare avanti e P per tornare indietro, mentre con le frecce ti sposti nel codice, selezionando l'indirizzo dell'istuzione nella prima linea in alto;

axt [addr] find data/code references to this address
axf [addr] find data/code references from this address


next [count]

// Continue to the next source line in the current (innermost) stack frame. This is similar to step, but function calls that appear within the line of code are executed without stopping. Execution stops when control reaches a different line of code at the original stack level that was executing when you gave the next command. This command is abbreviated n.

// An argument count is a repeat count, as for step.

004005ef <+50>:    mov    rax,QWORD PTR [rbp-0x10]
004005f3 <+54>:    add    rax,0x8
004005f7 <+58>:    mov    rax,QWORD PTR [rax]
004005fa <+61>:    mov    esi,0x4006da
004005ff <+66>:    mov    rdi,rax
00400602 <+69>:    call   0x4004b0 <strcmp@plt>

(gdb) b main

(gdb) run BBBB

(gdb) b *0x0000000000400602

(gdb) n

(gdb) x/10s $rsi
0x4006da:    "AAAA-Z10N-42-OK"
0x4006ea:    "Access Granted!"

la strcmp viene fatta tra i due registri rsi e rdi, e ritorna zero se contengono stringhe uguali;

ltrace ./license_1 AAAA
__libc_start_main(0x4005bd, 2, 0x7ffccebfc2d8, 0x400640 <unfinished ...>
printf("Checking License: %s\n", "AAAA"Checking License: AAAA
)                                                  = 23
strcmp("AAAA", "AAAA-Z10N-42-OK")                                                         = -45
puts("WRONG!"WRONG!
)                                                                            = 7
+++ exited (status 0) +++ 

C Code

#include <string.h>
#include <stdio.h>

int main(int argc, char *argv[]) {
        if(argc==2) {
        printf("Checking License: %s\n", argv[1]);
        if(strcmp(argv[1], "AAAA-Z10N-42-OK")==0) {
            printf("Access Granted!\n");
        } else {
            printf("WRONG!\n");
        }
    } else {
        printf("Usage: <key>\n");
    }
    return 0;
}
 


substring.c
===========

#include <stdio.h> // librerie standard input/output

// il main ti fa inserire una stringa, poi una posizione from, primo carattere? nesimo carattere? e un numero n, cioè quanti caratteri andare a considerare per la sottostringa partendo dal from;

int substring(char *source, int from, int n, char *target) {

int length, i;

// qui si calcola la lunghezza della stringa immessa come input, scorre la stringa, carattere dopo carattere fino al byte null;

for (length=0; source[length]!='\0'; length++);

// se il from immesso è maggiore della lunghezza della stringa appena calcolata, esce fuori con un codice di errore 1;

if (from>length) {
printf("Starting index is invalid.\n");
return 1;
}

// se (from + n) è un numero maggiore della lunghezza calcolata, imposta n, al massimo n possibile, in modo da raggiungere la fine della stringa;

if ((from+n)>length) {
n = (length - from);
}

// partendo da from, per tutti gli n caratteri, copia il carattere sorgente nella stringa target;

for (i=0; i target[i]=source[from+i];
}

// finalizza la stringa target con il byte null;


target[i]='\0';

return 0;

}


int main(int argc,char *argv[]) {

char str[100], targetString[100];
int from, n;

printf("Enter any string:");

// la funzione gets è una funzione non sicura, andrebbe usata la funziona fscanf;

gets(str);

printf("Enter from index (count from 0): ");
scanf("%d",&from);

printf("Enter number of characters: ");
scanf("%d",&n);

// se la funzione substring ritorna un valore 0, stampa la sottostringa estratta dalla stringa immessa;

if (substring(str, from, n, targetString) == 0) {
printf("Substring is: %s\n",targetString);
}

return 0;

}