NFC Reader
NFC Tools

Lack of security protection of communication. Most NFC communications do not include encryption mechanisms during its data exchange, it relies on the short range (i.e., less than 4 cm) to guarantee absence of eavesdropping attacks. However, the attacker can still place the device (i.e., NFC tag or NFC reader/writer) between client and NFC provider (i.e., NFC contactless point-of-sale) to trigger a specific attack such as eavesdrop, URL/URI spoofing. This vulnerability can also be exploited to jam the data exchange between two parties by sending out specific packet at the right timing, which can lead to a deny-of-service (DoS) attack toward the NFC- service provider.

URL/URI spoofing. The authors show that spoofing attacks can be performed to trick the user to see the false information as a valid one. In example, the attacker will design an exactly copy of a user’s trusted website with an almost equal URL so the user does not see the difference if she is not cautious. In addition, to uniform resource identifier (URI) and uniform/universal resource locater (URL) spoofing the research shows that phone call and text-message spoofing using the NFC protocol are also applicable. Furthermore, URI and URL spoofing are specially useful in combination with other attacks (i.e., cross-site request forgery).

Lack of authentication mechanism of NFC device. When the NFC reader reads information from another NFC-enabled device, there is not any authentication mechanisms available. Therefore, there is a potential risk of tag replacement and tag hiding (TRTH) attack. In the TRTH scenario, the NFC tags are overwritten by an attacker with malicious information or the physical tag is replace with another tag prepared by the attacker.

Automatic and non-user intervention URL/URI connection. The proposed attack takes advantage of the non-user inter- vention when the device detects another NFC device in its proximity. The malicious NFC provides an URL/URI to attack the user’s device, as the Android system does not request any user intervention, the device will automatically open the provided link by either other smartphone or NFC-tag. This situation opens security and privacy threads for the device’s owner. Once, the device opens the link, it can be attacked by fingerprinting mechanisms or share the user’s location for example (see more details in Section IV. The URI can also open application services such as contacts to automatically add malicious contacts without user permission request.

The attack can be achieved placing NFC-tags that unlocked Android devices will read in several locations: (1) public transport: in areas where the public transport uses NFC reader we can track user’s movement from one station to another, collect the user’s routine information (i.e., when the user goes to work and back home, where does he work); (2) coffee shop, poster at shopping mall : placing NFC-tags under coffee tables or in locations where users tend to leave the device unlocked, we can collect not only device’s information but also the geo-location as we know where the tag is located. For both situations, we can also collect the mentioned social network profiles or leverage more complex attacks in combination with other documented browser vulnerabilities.

Esercizio 1, pagina 11

Fino alla linea 7, lo snippet calcola la lunghezza della stringa; nella seconda parte viene fatto un memset(str, ch, len); per l'intera lunghezza della stringa viene scritto il carattere x;

01 : mov edi, [ebp+8]

questa istruzione copia nel registro edi, il puntatore al primo parametro della funzione, che è il puntatore alla stringa

02 : mov edx, edi

salva una copia di edi, quindi del puntatore alla stringa

03 : xor eax, eax

azzera eax, eax = 0

04 : or ecx, 0FFFFFFFFh

ecx = -1

05 : repne scasb

partendo da edi, scasb, cerca in memoria il byte in eax; dopo ogni comparazione di un byte, incrementa ecx e il valore di edi; nell'esempio viene cercato il byte null presente in eax; alla fine del processo ecx, dopo aver aggiunto 2 (-1 e byte null) e dopo averlo negato vale 64, che è la lunghezza della stringa;

06 : add ecx, 2
07 : neg ecx

gdb-peda$ p/d $ecx
$1 = 64

quindi abbiamo calcolato la lunghezza della stringa;

08 : mov al, [ebp+0Ch]

al = "x"

09 : mov edi, edx

edi punta nuovamente all'inizio della stringa;

10 : rep stosb

viene copiato il char x, in ogni byte della stringa partendo da edi; viene fatto esattamente ecx volte;

11 : mov eax, edx

viene copiato il puntatore alla stringa in eax; la funzione ritorna attraverso eax il puntatore alla stringa;


SECTION  .data
    db     'Radical Edward Project. Reverse Engineering Project. RE Project.', 0
SECTION  .text
GLOBAL _start
    push byte 'x'      ; second function parameter
    push dword my_str  ; first function parameter
    call black_out     ; call function
    add esp, 8         ; cleaning out the stack
    mov  ebx,0         ; parameter for exit call (return value)
    mov  eax,1         ; exit system call
    int 080h           ; run system call, see page 79 pal

    push ebp           ; function prologue, save stack base pointer
    mov ebp, esp       ; point base pointer to ESP  
    ; ------------ start code from book ---------
    mov edi, [ebp+8]
    mov edx, edi    
    xor eax, eax    
    or ecx, 0FFFFFFFFh
    repne scasb      
    add ecx, 2      
    neg ecx          
    mov al, [ebp+0Ch]
    mov edi, edx    
    rep stosb        
    mov eax, edx    
    ; ------------ end code from book -----------
    mov esp, ebp       ; restore stack pointer
    pop ebp            ; restore stack base pointer

return address     [ebp+4]
parametro 1 funzione  [ebp+8]
parametro 2 funzione  [ebp+C]

$ nasm -f elf32 -g -F dwarf radical.asm
$ ld -m elf_i386 -o radical radical.o

gdb -q prova

break *_start

(gdb) s
8    push byte 'x'    
(gdb) s
9    push dword my_str

gdb-peda$  x/cs $esp
0xffffd29c: "x"

(gdb) s
10    call black_out     ; call function
gdb-peda$  x/xw $esp
0xffffd298: 0x080490c0
gdb-peda$ x/s 0x080490c0
0x80490c0 <my_str>: "Radical Edward Project. Reverse Engineering Project. RE Project."


#include <stdio.h>

char* black_out(char *str, char ch)
    /* find length of string */
    int len = 0;
    char *str_cpy = str;
    while (*str_cpy != '\0') {
    /* set each character of string to <ch> */
    while (len-- > 0) {
        str[len] = ch;
    return str;

int main (int argc, char *argv[] )
    if (argc != 3 )
        printf("usage: %s string character", argv[0]);
    else {
        char *test2 = black_out(argv[1], *argv[2]);
        printf("%s\n", test2);


char* black_out(char *str, char ch)
    /* find length of string */
    int len = strlen(str);
    /* set each character of string to  */
    memset(str, ch, len);
    return str;

the term “hacker” has evolved quite dramatically over the years as the public’s awareness of technology has increased and as a sensationalist mass media continues to color the public’s opinion of hackers. In the beginning, a hacker was someone who worked passionately for the sake of curiosity and exploration. There were hardware hackers who took it upon themselves to remove the covers from computers to optimize their design (early computers were built out of discrete components, so they could be modified in meaningful ways with simple tools), and there were software hackers who labored to make the most compact and elegant code, since computational resources were scarce and slow. There were hackers who explored the ins and outs of the phone system, and those who explored the roofs and tunnels of buildings of university campuses. Quite often, early hackers engaged in all of these activities. Hackers would share their findings or results (hacks) with each other freely, as their rewards were not financial, but came from satisfying their intellectual curiosity and from the enthusiasm of their peers. As a result, hackers tended to form into meritocratic groups where member- ship and advancement were based entirely upon a person’s ability to hack.

As technology evolved and computers became faster and more inte- grated, hackers found that the effort involved in hardware hacking was not worth the benefits. The interesting pieces of computers were quickly becoming buried deep within hermetically sealed ceramic packages, etched into silicon structures that were difficult to see even with a good microscope. A difficult hardware hack that might double the perfor- mance of a computer was made moot within months by Moore’s Law. On the other hand, software hacking was beginning to focus more on applications and less on algorithms or optimization. The compactness or elegance of a program was no longer directly important as memory and processor power became cheap and plentiful. Besides, compiler technol- ogy had also improved to the point where compiled code ran almost as fast as hand assembly. By the late 80’s, the term “hacker” had grown to imply someone who could write volumes of C code in their sleep and create brilliant applications overnight. The old hardware hackers were either converting to software hackers, or retreating to university labs and corporations that could afford to support their expensive hobbies.

The term “hacker” at that time was increasingly associated with people who cracked passwords and programs to gain access to machines and software that was otherwise off limits. Hollywood was partly responsible for this stereotype, with a slew of movies that portrayed teenagers bringing the world to the brink of nuclear annihilation with a few keystrokes, or closet geniuses creating artificially intelligent cyber- monsters in their basement. 4 Unfortunately, the hyberbole of these movie plots was lost on the general public, and this dark impression of hackers eventually became a dominant part of the hacker stereotype. The inaccuracy of this stereotype contributed to the creation of a term for hackers that focuses primarily upon cracking systems and programs “crackers.”

Linux-RE-101 documenti sul mondo del Reverse Engineering di Linux; RE 101


Work in progress as I am actively collecting these.

#### Keep these handy

- Describes how all syscalls for all architectures work (what registers are for input, output, error, ..)
- "Executable and Linkable Format (ELF)" or (I like .txt more)
- "Linux Cross Reference"
- "Syscall table reference"
- "System V ABI x86-64 Linux"
- "MIPS documentation"
- "ELF for the ARM"
- "ELF for the ARM64"
- "How to write shared libraries" by Ulrich Drepper  

#### Must read

- "The 101 of ELF Binaries on Linux: Understanding and Analysis"
- ELF101 from Corkami (Ange Albertini)
- "How programs get run: ELF binaries"
- "How statically linked programs run on Linux"
- "A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux"
- "The Definitive Guide to Linux System Calls"
- "Linux on the Half-ELF"
- "Learning Linux Binary Analysis" by Ryan O'Neill

#### 101

- *Optional*: "Guide to x86 assembly"
- *Optional*: "Assembly x86_64 programming for Linux"
- *Optional*: x64 assembly
- *Optional*: "Step by step to MIPS assembly"
- *Optional*: FreeBSD Assembly Language Programming
- *Optional*: "Linux MIPS ELF reverse engineering tips"
- "The dissection of a simple hello world ELF file" and "ELF101"
- "The 101 of ELF Binaries on Linux: Understanding and Analysis"
- "A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux"
- "The definitive guide to linux system calls"
- "Anatomy of a system call, part 1"
- "Anatomy of a system call, part 2"
- "About ELF auxiliary vectors"
- "How programs get run: ELF binaries"
- "Linux x86 Program Start Up"
- "How statically linked programs run on Linux"
- "Startup state of a Linux/i386 ELF binary" and
- "Stack frame layout on x86-64"
- "What is"
- "Understanding "
- "Linux process states"

#### 201

- *Optional*: "Linkers - 20 parts"
- "Static linking (x86) internals"
- "Static linking (x86_64) internals"
- "Dynamic linking and x86_64 internals"
- "Dynamic linking (x86) internals"
- "PLT and GOT - they key to code sharing and dynamic libraries"
- "Understanding x64 code models"
- "Load-time relocation of shared libraries "
- "Position Independent Code (PIC) in shared libraries "
- "Position Independent Code (PIC) in shared libraries x64"
- "Relocations, relocations"
- *Good night reading*: "Linux on the Half-ELF"

#### Packers, obfuscation, and encryption

- "Runtime binary encryption"
- "Next-Gen Runtime Binary Encryption"
- "Binary Protection Schemes"
- "Shiva - Advances in ELF Binary Encryption"
- "Burneye protector"
- "ELF Encrypter"
- "midgetpack is a multiplatform secure ELF packer"
- "ELF Binary Code Injection, Loader/'Decrypter'"

#### Exploitation

- "Linux x86 Reverse Engineering - Shellcode Disassembling and XOR decryption"
- "Shellcoding in Linux"
- "Linux (x86) Exploit Development Series"
- "Linux 64-bit Return Oriented Programming"
- "Introduction to Return Oriented Programming (ROP)"
- "Linux x64 Infection for Lamers (by a Lamer)"
- "Linux Kernel ROP - Ropping your way to # (Part 1) "
- "Linux Kernel ROP - Ropping your way to # (Part 2)"
- "Practice and learning in the world of C RE and exploit analysis"
- "Modern Binary Exploitation" (not strictly related to Linux)
- "Advanced exploitation on Linux: ROP and infoleaks"

#### Anti techniques

- "Beginners guide to basic Linux anti anti debugging techniques"
- "Kickers of ELF"
- "ELF header abuse"
- "Toolkit to detect/crash/attack GNU debugging-related tools"
- "ELF: dynamic struggles" ""
- "ptrace() tutorial"
- "ptrace() on 64-bit system"
- "Linux x86 run-time process manipulation"
- "Cheating the ELF Subversive Dynamic Linking to Libraries"
- "gdb leaves file descriptors open in debugee"
- "More GDB Anti-Debugging"
- "How to detect virtualization on Linux"
- "Mechanisms to determine VMWare VM"

#### Viruses & infection techniques

- "Linux viruses - ELF file format" by Marius Van Oers
- "Abusing .CTORS and .DTORS for fun 'n profit"
- "The WIT virus" In Linux PDFs/The WIT Virus.pdf
- "Caveat virus"
- "Reverse of a coin: A short note on segment alignment"
- "INT 0x80? No, thank you! aka Pilot"
- "Infecting ELF-files using function padding for Linux"
- "Injected Evil (executable files infection)"
- "An unofficial analysis of the Retaliation Virus (Authored by JPanic)" or
- "Skeksi virus"
- "Modern Day ELF Runtime infection via GOT poisoning"
- "From position-independent to self-relocatable viral code"
- "The Cerberus ELF interface"
- "Malicious Code Injection via /dev/mem"
- VX Heaven collection of viruses
- Source code of infection techniques by herm1t

#### Linux kernel, rootkits, and LKM development

- *Optional*: "A series of posts about the linux kernel and its insides."
- *Optional*: "Kernel hacking HOWTO"
- "Anatomy of the Linux kernel"
- "Linux process management"
- "Linux processes"
- "Kernel hacking"
- "Be a kernel hacker"
- "Day 5: I wrote a kernel module"
- "Linux Rootkits 101"
- "Linux Rootkits 201"
- "Linux Rootkits 301"
- "Handling Interrupt Descriptor Table for fun and profit"
- "Intercepting System Calls and Dispatchers – Linux"
- "Linux Kernel Rootkits"
- "Linux Kernel Debugging using KGDB/GDB"
- "Kernel instrumentation using kprobes"
- "Infecting loadable kernel modules versions 2.6.x/3.0.x"
- "(nearly) Complete Linux Loadable Kernel Modules"
- Check the README for more
- "UNIX and Linux based rootkits"
- "Sample rootkit for linux"
- "Writing a LKM rootkit that uses LSM hooks"
- "TCP/UDP symmetric encryption tunnel wrapper"
- "Userland rootkit based off of the original LD_PRELOAD technique from Jynx rootkit"
- "an experimental linux kernel module (rootkit) with a keylogger and built-in IRC bot"
- "An LKM rootkit targeting Linux 2.6/3.x on x86(_64), and ARM"
- "Linux rootkit adapted for 2.6 and 3.x"
- "Linux: Creating an entry in /proc file system (Part 1: The hello_proc pseudo file)"
- Answer to "Ripping out the hidden kernel module by reading kernel memory directly?"
- "User space memory access from the Linux kernel"
- "get_user_pages example"
- "Horse Pill: A New Type Of Linux Rootkit"
- "vlany, Linux (LD_PRELOAD) rootkit"
- "Hacking the wholism of GNU/Linux net*"
- "Linux Device Drivers"
- "Linux Data Structures"
- "Status of the Kernel Self Protection Project"

#### Crackmes and challenges

- "Exercises for learning Reverse Engineering and Exploitation."
- "IOLI crackme"
- from "Modern Binary Exploitation"
- "Exercises" section in

#### Analyzes, "hands-on", analysis techniques

- "100 GDB tips"
- "Defeating IOLI with Radare2"
- "Using radare2 to pwn things"
- "Pwning With Radare2"
- "At Gunpoint Hacklu 2014 With Radare2"
- "manual binary mangling with radare"
- "Analysis of an unknown binary, for the HoneyNet Reverse Challenge"
- "Reversing GO binaries like a pro"
- "Reversing Golang"
- "Reversing Linux Malware" (includes Golang reversing with radare2)
- "Reverse Engineering With Radare2 – Part 2"
- "Reverse Engineering With Radare2 – Part 3"

#### Research and development
- binary samples for testing
- "ELF Eccentricities - Julian Bangert, Sergey Bratus"
- "ELF-Miner: Using structural knowledge and data mining methods to detect new (Linux) malicious executables"
- "Fuzzing the ELF file format with Melkor"
- (all of it)
- "Effective file format fuzzing" (not related to Linux directly, but it's pretty great)
- "Linux kernel sanitizers and syscall fuzzer"
- "ElfParser blog"
- "ELF vs. Mach-O"
- "ELF vs. Mach-O 2"
- "Where did the fork go?"
- "Playing with ptrace, part II"
- "Write Yourself an Strace in 70 Lines of Code"
- "Writing a Linux Debugger Part 1: Setup"
- "Writing a Linux Debugger Part 2: Breakpoints"
- "Writing a Linux Debugger Part 3: Registers and memory"
- "Writing a Linux Debugger Part 4: Elves and dwarves"

#### Tools

- "Quickly determine the capabilities of an ELF binary through static analysis"
- "LIEF (Library to Instrument Executable Formats)"
- "[shmcat] Dumps the contents of a SysV shared memory segment"
- "ld-linux code injector"
- "Measuring Linux at Runtime" coupled with
- "Linux Rootkit Scanner"
- "tool to locally check for signs of a rootkit"
- "a Unix-based tool that scans for rootkits, backdoors and possible local exploits"
- "MoVP 1.5 KBeast Rootkit, Detecting Hidden Modules, and sysfs "

#### Other

- "Building a concrete alternative to IDA - Radare2 to the rescue!"
- "Introduction to Reverse Engineering Software in Linux"
- "Radare2 book"
- "Intro to Radare2"
- "Radare2 baby steps"
- "Radare A to Z"
- &
- "Emulating Linux MIPS in Perl"
- "Crypto 101"
- "REMnux 6"
- "Why is the ELF execution entry point virtual address of the form 0x80xxxxx and not zero 0x0?"
- "Why do virtual memory addresses for linux binaries start at 0x8048000?"

#### Books
- "Malware Forensics Field Guide for Linux Systems" by Cameron H. Malin, Eoghan Casey, James M. Aquilina
- "Linux (Bezpečnosť a exploity)" by Miroslav Dobšíček and Radim Ballner
- "Hacking: The Art of Exploitation" by Jon Erickson
- "The Shellcoder's Handbook: Discovering and Exploiting Security Holes" by Chris Anley, John Heasman, Felix Lindner
- "The Linux Programming Interface" by Michael Kerrisk
- "Learning Linux Binary Analysis" by Ryan O'Neill
SECTION  .data
    db     'The pool on the roof must have a leak.', 0
SECTION  .text
GLOBAL _start
    push byte 'x'      ; second function parameter
    push dword my_str  ; first function parameter
    call black_out     ; call function
    add esp, 8         ; cleaning out the stack
    mov  ebx,0         ; parameter for exit call (return value)
    mov  eax,1         ; exit system call
    int 080h           ; run system call, see page 79 pal

    push ebp           ; function prologue, save stack base pointer
    mov ebp, esp       ; point base pointer to ESP  
    ; ------------ start code from book ---------

    mov edi, [ebp+8]  
;  mette in edi l'indirizzo del primo parametro della funzione
    mov edx, edi        
; backup dell'indirizzo
    xor eax, eax          
; azzera eax
   or ecx, 0FFFFFFFFh
; mette a -1 ecx

   repne scasb              
;  scansiona tutta la stringa fino al byte null 0 presente in eax  
   add ecx, 2              
   neg ecx                     ; nega ecx, 38

   mov al, [ebp+0Ch]  
; copia il carattere presente in ebp+12
   mov edi, edx            
; rimette in edi l'indirizzo dell'inizio della stringa

   rep stosb                  
; riempie la stringa di x        
   mov eax, edx          
; copia l'indirizzo della stringa in eax che ritorna il valore della funzione    

   ; ------------ end code from book -----------
   mov esp, ebp       ; restore stack pointer
   pop ebp            ; restore stack base pointer

Playing a very basic level of a known wargame the other day I was trying to solve the following problem:
Given an executable (ELF, Linux) which accepts a password as an argument and verifies if this is correct, find this string. As most of the problems, it’s quite easy if you have the right tools (and knowledge of course).
Anyway, I thought the solution(s) would make a nice blog entry, so here it is!
In order to play around with it in my own Ubuntu, I wrote a very simple C program, named pass_cli.c

carlos@dell:~/Dropbox/hacking/wargames$ cat pass_cli.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
main(int argc, char **argv)
char password[] = “yomama”;
if(argc < 2)
printf(“Usage: %s <password>\n”, argv[0]);
if(strncmp(argv[1], password, strlen(password)))
} else {
return(0); // never reached :)
I compiled the program with no special options.
carlos@dell:~/Dropbox/hacking/wargames$ file pass_cli
pass_cli: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped
A first tool of the trade when you are looking for strings in a binary is strings, which will look for strings of printable characters inside the binary.
carlos@dell:~/Dropbox/hacking/wargames$ strings pass_cli
Usage: %s <password>
Well, we cannot find the password here (and even if it were displayed here, how could you identify it?) but that gave us some preliminar information about the program. We can see some familiar libc functions (printf, strlen, strncmp, etc.), strncmp will be of interest a bit later.
Another method you could have tried is for example to dump the contents of the .text section inside the binary. This is actually the same idea behind the use of strings, just a lot messier ;)
Remember that the .text section of a binary contains the machine instructions (the compiled code) but that doesn’t mean the strings are neccesarily stored in a readable way. Anyway we could check the contents of this section with the help of objdump.
carlos@dell:~/Dropbox/hacking/wargames$ objdump

-h, –[section-]headers  Display the contents of the section headers

-T, –dynamic-syms       Display the contents of the dynamic symbol table

carlos@dell:~/Dropbox/hacking/wargames$ objdump -h pass_cli

13 .text         000001fc  08048400  08048400  00000400  2**4   <—- here

This section starts at the address 0x08048400, that is, the offset is 0x400 (the start virtual address is 0x08048000)
Armed with this knowledge we could hexdump this section and manually inspect it
carlos@dell:~/Dropbox/hacking/wargames$ hexdump -C -s 0x400 pass_cli | less

000004c0  19 79 6f 6d 61 66 c7 44  24 1d 6d 61 c6 44 24 1f  |.yomaf.D$.ma.D$.| <—   :(
As we can see, the string isn’t stored in a readable format, as expected :(
A very useful tool in this case is “ltrace” for we can monitor every system call (with the corresponding arguments!)
carlos@dell:~/Dropbox/hacking/wargames$ ltrace ./pass_cli AAAAA
__libc_start_main(0x80484b4, 2, 0xbf952854, 0x8048570, 0x8048560 <unfinished …>
strlen(“yomama”)                                                   = 6
strncmp(“AAAAA”, “yomama”, 6)                                      = -1      <— TA-DA!!!! :)
)                                                       = 5
exit(1 <unfinished …>
+++ exited (status 1) +++
But what if our system doesn’t have this tool? Then we have to take the heavy weapons and perform some elegant debugging :)
carlos@dell:~/Dropbox/hacking/wargames$ objdump -T pass_cli
pass_cli:     file format elf32-i386
00000000  w   D  *UND*  00000000              __gmon_start__
00000000      DF *UND*  00000000  GLIBC_2.0   __libc_start_main
00000000      DF *UND*  00000000  GLIBC_2.0   strlen
00000000      DF *UND*  00000000  GLIBC_2.0   printf
00000000      DF *UND*  00000000  GLIBC_2.0   puts
00000000      DF *UND*  00000000  GLIBC_2.0   strncmp     <—- idea!
00000000      DF *UND*  00000000  GLIBC_2.0   exit
0804861c g    DO .rodata        00000004  Base        _IO_stdin_used
We have very good reasons to suspect that strncmp is being used to check our input against the password so let’s start the program in gdb and quickly disassemble it in order to localize the call to strncmp.
carlos@dell:~/Dropbox/hacking/wargames$ gdb -q ./pass_cli
Reading symbols from /home/carlos/Dropbox/hacking/wargames/pass_cli…(no debugging symbols found)…done.
(gdb) set disassembly-flavor intel <—- PLEASE ;)
(gdb) disass main
Dump of assembler code for function main:
0x080484b4 <+0>: push ebp
0x080484b5 <+1>: mov ebp,esp
0x080484b7 <+3>: and esp,0xfffffff0
0x080484ba <+6>: sub esp,0x20
0x080484bd <+9>: mov DWORD PTR [esp+0x19],0x616d6f79
0x080484c5 <+17>: mov WORD PTR [esp+0x1d],0x616d
0x080484cc <+24>: mov BYTE PTR [esp+0x1f],0x0
0x080484d1 <+29>: cmp DWORD PTR [ebp+0x8],0x1
0x080484d5 <+33>: jg 0x80484f9
0x080484d7 <+35>: mov eax,DWORD PTR [ebp+0xc]
0x080484da <+38>: mov edx,DWORD PTR [eax]
0x080484dc <+40>: mov eax,0x8048620
0x080484e1 <+45>: mov DWORD PTR [esp+0x4],edx
0x080484e5 <+49>: mov DWORD PTR [esp],eax
0x080484e8 <+52>: call 0x80483bc
0x080484ed <+57>: mov DWORD PTR [esp],0x1
0x080484f4 <+64>: call 0x80483ec
0x080484f9 <+69>: lea eax,[esp+0x19]
0x080484fd <+73>: mov DWORD PTR [esp],eax
0x08048500 <+76>: call 0x80483ac
0x08048505 <+81>: mov edx,eax
0x08048507 <+83>: mov eax,DWORD PTR [ebp+0xc]
0x0804850a <+86>: add eax,0x4
0x0804850d <+89>: mov eax,DWORD PTR [eax]
0x0804850f <+91>: mov DWORD PTR [esp+0x8],edx
0x08048513 <+95>: lea edx,[esp+0x19]
0x08048517 <+99>: mov DWORD PTR [esp+0x4],edx
0x0804851b <+103>: mov DWORD PTR [esp],eax
0x0804851e <+106>: call 0x80483dc
0x08048523 <+111>: test eax,eax
0x08048525 <+113>: je 0x804853f
0x08048527 <+115>: mov DWORD PTR [esp],0x8048636
Now I will place a breakpoint exactly on the address of this call instruction.
(gdb) b *0x0804851e
Breakpoint 1 at 0x804851e
Remember to use the asterisk (*) right in front of the address, so gdb understands what follows isn’t a literal.
Why did I do it this way? Think about it the other way. What happens when the call instruction is executed? The whole stack frame stup parafernalia, namely
EIP is pushed to the stack (by the call itself)
The function prologue is executed, that is
the current value of EBP is pushed to the stack (from now on, known as SFP)
the current value of ESP passes to be the new EBP (“a new stack frame starts here”)
a value is subtracted from ESP (to allocate space for local variables)
That is too messy to keep track of, so if we stop the execution flow right before the call instruction, what we have is the stack right before all this stuff… the function arguments at the top of the stack ;)
(gdb) run AAAAAA
Starting program: /home/carlos/Dropbox/hacking/wargames/pass_cli AAAAAA
Breakpoint 1, 0x0804851e in main () <— breakpoint is hit
(gdb) info reg
eax 0xbffff620 -1073744352
ecx 0x6 6
edx 0xbffff3c9 -1073744951
ebx 0x283ff4 2637812
esp 0xbffff3b0 0xbffff3b0 <— “top” of the stack
ebp 0xbffff3d8 0xbffff3d8
esi 0x0 0
edi 0x0 0
eip 0x804851e 0x804851e
eflags 0x286 [ PF SF IF ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51
Let’s examine the top of the stack. We are actually interested in the first three words.
(gdb) x/12x $esp
0xbffff3b0: 0xbffff620 0xbffff3c9 0x00000006 0xbffff3d8
0xbffff3c0: 0x0015d4a5 0x0011e0c0 0x6d6f797b 0x00616d61
0xbffff3d0: 0x08048570 0x00000000 0xbffff458 0x00144bd6
Without further inspection we can see a 6, the number of char the function has to compare. It looks good at least ;) Let’s remember the exact syntaxis of strncmp()
carlos@dell:~/Dropbox/hacking/wargames$ man 3 strncmp
int strcmp(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t n); <— allright, three arguments…
Also one of the first two words must be a pointer to the hardcoded password, the other a pointer to the user input (argv[1] in this case)
(gdb) x/4x 0xbffff620
0xbffff620: 0x41414141 0x4f004141 0x54494252 0x434f535f
Well, this is pretty clearly our string of 6 “A’s” null-terminated. The other address must be the location of our password!
(gdb) x/4x 0xbffff3c9
0xbffff3c9: 0x616d6f79 0x7000616d 0x00080485 0x58000000
OK, another string of 6 characters, null-terminated. The ASCII char  associated to these values can be displayed in gdb as follows:
(gdb) p/c *0xbffff3c9
$16 = 121 ‘y‘
(gdb) p/c *0xbffff3ca
$17 = 111 ‘o‘
(gdb) p/c *0xbffff3cb
$18 = 109 ‘m‘
(gdb) p/c *0xbffff3cc
$19 = 97 ‘a‘
(gdb) p/c *0xbffff3cd
$20 = 109 ‘m‘
(gdb) p/c *0xbffff3ce
$21 = 97 ‘a‘
(gdb) p/c *0xbffff3cf
$22 = 0 ‘00‘

So here’s the magic password! YOMAMA! ;)
strings[0] = (0x78 ^ 0x34)

strings[1] = (0x31)

strings[2] = (0x7c ^ 0x32)

strings[3] = (0xdd ^ 0x88)

strings[4] = (0x58)

strings[5] = null

          0x08048451      55               push ebp

          0x08048452      89e5             mov ebp, esp

          0x08048454      0fb60521a00408   movzx eax, byte [0x804a021]    ; strings[1]

          0x0804845b      3c31             cmp al, 0x31                   ; 0x31 ?

      ,=< 0x0804845d      740a             jz 0x8048469                   ; not match

      |   0x0804845f      b800000000       mov eax, 0x0

      |   0x08048464      e98c000000       jmp dword 0x80484f5

      `-> 0x08048469      0fb60520a00408   movzx eax, byte [0x804a020]    ; strings[0]

          0x08048470      83f034           xor eax, 0x34                  ; xor 0x34

          0x08048473      a220a00408       mov [0x804a020], al            ; store res[0]

          0x08048478      0fb60522a00408   movzx eax, byte [0x804a022]    ; strings[2]

          0x0804847f      83f032           xor eax, 0x32                  ; xor 0x32

          0x08048482      a222a00408       mov [0x804a022], al            ; store res[2]

          0x08048487      0fb60523a00408   movzx eax, byte [0x804a023]    ; strings[3]

          0x0804848e      83f088           xor eax, 0xffffff88            ; xor 0x88

          0x08048491      a223a00408       mov [0x804a023], al            ; store res[3]

          0x08048496      0fb60524a00408   movzx eax, byte [0x804a024]    ; strings[4]

          0x0804849d      3c58             cmp al, 0x58                   ; 0x58 ?

      ,=< 0x0804849f      7407             jz 0x80484a8                   ; match

      |   0x080484a1      b800000000       mov eax, 0x0

      |   0x080484a6      eb4d             jmp 0x80484f5

      `-> 0x080484a8      0fb60525a00408   movzx eax, byte [0x804a025]    ; strings[5]

          0x080484af      84c0             test al, al                    ; null ?

     ,==< 0x080484b1      7407             jz 0x80484ba                   ; match

     |    0x080484b3      b800000000       mov eax, 0x0

     |    0x080484b8      eb3b             jmp 0x80484f5

     `--> 0x080484ba      0fb60522a00408   movzx eax, byte [0x804a022]    ; res[2]

          0x080484c1      3c7c             cmp al, 0x7c                   ; 0x7c ?

    ,===< 0x080484c3      7407             jz 0x80484cc

    |     0x080484c5      b800000000       mov eax, 0x0

    |     0x080484ca      eb29             jmp 0x80484f5

          0x080484cc      0fb60520a00408   movzx eax, byte [0x804a020]    ; res[0]

          0x080484d3      3c78             cmp al, 0x78                   ; 0x78 ?

      ,=< 0x080484d5      7407             jz 0x80484de

      |   0x080484d7      b800000000       mov eax, 0x0

     ,==< 0x080484dc      eb17             jmp 0x80484f5

     |`-> 0x080484de      0fb60523a00408   movzx eax, byte [0x804a023]    ; res[3]

     |    0x080484e5      3cdd             cmp al, 0xdd                   ; 0xdd ?

    ,===< 0x080484e7      7407             jz 0x80484f0

    ||    0x080484e9      b800000000       mov eax, 0x0

   ,====< 0x080484ee      eb05             jmp 0x80484f5

   |`---> 0x080484f0      b801000000       mov eax, 0x1

   `-`--> 0x080484f5      5d               pop ebp

          0x080484f6      c3               ret


8048450: c3                    ret  

 8048451: 55                    push   %ebp

 8048452: 89 e5                 mov    %esp,%ebp

 8048454: 0f b6 05 21 a0 04 08  movzbl 0x804a021,%eax

 804845b: 3c 31                 cmp    $0x31,%al

 804845d: 74 0a                 je     8048469 <__isoc99_scanf@plt+0xf9>

 804845f: b8 00 00 00 00        mov    $0x0,%eax

 8048464: e9 8c 00 00 00        jmp    80484f5 <__isoc99_scanf@plt+0x185>

 8048469: 0f b6 05 20 a0 04 08  movzbl 0x804a020,%eax

 8048470: 83 f0 34              xor    $0x34,%eax

 8048473: a2 20 a0 04 08        mov    %al,0x804a020

 8048478: 0f b6 05 22 a0 04 08  movzbl 0x804a022,%eax

 804847f: 83 f0 32              xor    $0x32,%eax

 8048482: a2 22 a0 04 08        mov    %al,0x804a022

 8048487: 0f b6 05 23 a0 04 08  movzbl 0x804a023,%eax

 804848e: 83 f0 88              xor    $0xffffff88,%eax

 8048491: a2 23 a0 04 08        mov    %al,0x804a023

 8048496: 0f b6 05 24 a0 04 08  movzbl 0x804a024,%eax

 804849d: 3c 58                 cmp    $0x58,%al

 804849f: 74 07                 je     80484a8 <__isoc99_scanf@plt+0x138>

 80484a1: b8 00 00 00 00        mov    $0x0,%eax

 80484a6: eb 4d                 jmp    80484f5 <__isoc99_scanf@plt+0x185>

 80484a8: 0f b6 05 25 a0 04 08  movzbl 0x804a025,%eax

 80484af: 84 c0                 test   %al,%al

 80484b1: 74 07                 je     80484ba <__isoc99_scanf@plt+0x14a>

 80484b3: b8 00 00 00 00        mov    $0x0,%eax

 80484b8: eb 3b                 jmp    80484f5 <__isoc99_scanf@plt+0x185>

 80484ba: 0f b6 05 22 a0 04 08  movzbl 0x804a022,%eax

 80484c1: 3c 7c                 cmp    $0x7c,%al

 80484c3: 74 07                 je     80484cc <__isoc99_scanf@plt+0x15c>

 80484c5: b8 00 00 00 00        mov    $0x0,%eax

 80484ca: eb 29                 jmp    80484f5 <__isoc99_scanf@plt+0x185>

 80484cc: 0f b6 05 20 a0 04 08  movzbl 0x804a020,%eax

 80484d3: 3c 78                 cmp    $0x78,%al

 80484d5: 74 07                 je     80484de <__isoc99_scanf@plt+0x16e>

 80484d7: b8 00 00 00 00        mov    $0x0,%eax

 80484dc: eb 17                 jmp    80484f5 <__isoc99_scanf@plt+0x185>

 80484de: 0f b6 05 23 a0 04 08  movzbl 0x804a023,%eax

 80484e5: 3c dd                 cmp    $0xdd,%al

 80484e7: 74 07                 je     80484f0 <__isoc99_scanf@plt+0x180>

 80484e9: b8 00 00 00 00        mov    $0x0,%eax

 80484ee: eb 05                 jmp    80484f5 <__isoc99_scanf@plt+0x185>

 80484f0: b8 01 00 00 00        mov    $0x1,%eax

 80484f5: 5d                    pop    %ebp

 80484f6: c3                    ret

;  hello.asm  a first program for nasm for Linux, Intel, gcc


; assemble: nasm -f elf -l hello.lst  hello.asm

; link:  gcc -o hello  hello.o

; run:         hello

; output is: Hello World

 SECTION .data  ; data section

msg: db "Hello World",10 ; the string to print, 10=cr

len: equ $-msg  ; "$" means "here"

    ; len is a value, not an address

 SECTION .text  ; code section

        global main  ; make label available to linker

_start:    ; standard  gcc  entry point


 mov edx,len  ; arg3, length of string to print

 mov ecx,msg  ; arg2, pointer to string

 mov ebx,1  ; arg1, where to write, screen

 mov eax,4  ; write command to int 80 hex

 int 0x80  ; interrupt 80 hex, call kernel


 mov ebx,0  ; exit code, 0=normal

 mov eax,1  ; exit command to kernel

 int 0x80  ; interrupt 80 hex, call kernel

nasm -g -f elf -F dwarf hello.asm
ld -m elf_i386 -o hello hello.o
per non far incartare il ddd, andare in .ddd
e modificare il file init :
set extended-prompt not set\n\  in
set prompt (gdb) \n\

winedbg --gdb --no-start Easy_CrackMe.exe

0024:0025: create process 'Z:\home\bz\Downloads\Easy_CrackMe.exe'/0x1106e8 @0x401188 (0<0>)

0024:0025: create thread I @0x401188

target remote localhost:45181


(gdb) target remote localhost:45181

objdump -D -M intel ./Easy_CrackMe.exe > out.asm

break *0x004010b0

4010b0:       80 7c 24 05 61        cmp    BYTE PTR [esp+0x5],0x61   "a"

4010b5:       75 7e                        jne    0x401135

4010b9:       8d 4c 24 0a           lea    ecx,[esp+0xa]

4010bd:       68 78 60 40 00        push   0x406078       "5y"

4010c2:       51                           push   ecx

4010c3:       e8 88 00 00 00        call   0x401150

4010d1:       be 6c 60 40 00        mov    esi,0x40606c      "R3versing"

40110d:       80 7c 24 04 45        cmp    BYTE PTR [esp+0x4],0x45   "E"

401112:       75 21                 jne    0x401135

$cat exit_shellcode.asm

Section         .text
global _start

mov ebx,0
mov eax,1
int 0x80

nasm -f elf exit_shellcode.asm
ld -m elf_i386 -o exit_shellcode exit_shellcode.o

objdump -d exit_shellcode

exit_shellcode:     file format elf32-i386

Disassembly of section .text:

08048060 <_start>:
8048060: bb 00 00 00 00       mov    $0x0,%ebx
8048065: b8 01 00 00 00       mov    $0x1,%eax
804806a: cd 80                 int    $0x80

per togliere i bytes null 00, si usa l'istruzione xor ebx,ebx per la prima istruzione, e il registro al per la seconda

xor ebx,ebx
mov al,1

$cat wack.c 

char shellcode[] = "\xbb\x00\x00\x00\x00"
int main()
int *ret;
ret = (int *)&ret +2;
(*ret) = (int)shellcode;

gcc -m32 -fno-stack-protector -z execstack -o wack wack.c 
strace ./wack

#include <IRremote.h>

#define POWER         0xE0E040BF
#define UNO           0xE0E0906F
#define TVKEY         0xE0E0D827
#define ZERO          0xE0E08877  
#define CHPIU         0xE0E048B7
#define CHMENO        0xE0E008F7
#define SAMSUNG_BITS  32

IRsend irsend;

void setup()
  pinMode (3, OUTPUT);  //output as used in library

void loop() {

irsend.sendSAMSUNG(REPEAT, 32); // Some receivers seem to respond a lot faster when a repeat is sent before the actual command.
delay(35); //This delay is needed for optimal response.
irsend.sendSAMSUNG(ZERO, 32); // hex value, 32 bits


Arduino-TVout library; invece della resistenza 470 Ohm ne ho usata una da 330 Ohm

#include <IRremote.h>

int RECV_PIN = 7;
int LED = 13;
int speakerPin = 3;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
  irrecv.enableIRIn(); // Start the receiver
  pinMode(LED, OUTPUT);

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);


  case 0xC0B92:

  case 0xFF629D:
    Serial.println(" CH             ");
    digitalWrite(LED, HIGH);
    digitalWrite(LED, LOW);
    irrecv.resume(); // Receive the next value

int LEDGreen=9;
int LEDBlue=10;
int LEDRed=11;

int sensorPin=0;
int val;

void setup(){

void loop(){

  if (val<150) {
  } else if (val<300) {
  } else if (val<450) {
  } else if (val<600) {
  } else if (val<750) {
  } else if (val<900) {