Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
143 views
84 slides
Jun 01, 2024
Slide 1 of 84
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
About This Presentation
coc2024
Size: 5.97 MB
Language: en
Added: Jun 01, 2024
Slides: 84 pages
Slide Content
Reverse Engineering & Pwnable for CTF Powered By: Kusol Watchara-Apanukorn
Kusol Watchara-Apanukorn (Boss) Head of Cyber Security Consultant @Sectrike Co., Ltd Certificate: OSCP, GPEN, eCXD, Python for Pentester Hobbies: IoT CVE Hunter Bug Bounty Hunter CTF LinkedIn Profile: https://th.linkedin.com/in/kusol-watchara-apanukorn-808094146 WHO AM I?
TABLE OF CONTENTS Basic Knowledge 01 Introduction 02 Basic of RE Reverse Engineer 03 Basic of PWN Pwnable 04 Summary
Introduction
Reverse Engineering Definition Reverse engineering is considered as the process of developing a set of specifications for a complex hardware system by an orderly examination of specimens of that system. It is assumed that the specifications are being developed for the purpose of making a clone of the original hardware system, a circumstance which requires the most comprehensive form of specifications. Ref: https://ieeexplore.ieee.org/abstract/document/6313354
Reverse Engineering Basic Knowledge for CTF Read pseudo -code Known some assembly Coding
Reverse Engineering Common language in CTF C C++ Rust Golang C# or .NET JAVA Python (pyc or py)
Low Level Language Manually memory management Communicate directly to hardware/os True low-level: Assembly and machine code These days, we category C and C++ are low-level language.
Reverse Engineering Common binary file PE file (.exe or .dll) ELF file (elf) APK file (apk) .NET file (.exe) JAVA file Python file (pyc or py)
Reverse Engineering Common Goal Search the hardcoded Modify the target program to change logic Analyze the program how it work? (This is between reverse engineering and pwnable) Hidden function Valid input to show the flag
Pwnable Aka Pwned/Pwn It’s a slang word that mean totally defeat or dominate. The earliest known use of the verb pwn is in the 1990s. The earliest evidence for pwn is from 1999, in a message posted on the Usenet newsgroup rec.games.computer.ultima.online. Ref: https://www.oed.com/dictionary/pwn_v?tl=true
Pwnable Basic knowledge Reverse engineering Read pseudo-code Known some assembly Coding Memory vulnerabilities like buffer overflow and format string
Pwnable Common binary file PE file (.exe or .dll) ELF file (elf) Python file (pyc or py)
Pwnable Common CTF Goal Analyze the program how it work? (This is between reverse engineering and pwnable) Hidden function Valid input to show the flag Time attack Exploit memory vulnerability program like: Buffer overflow in ARM, x86, x86_64 Format string vulnerability Return-oriented programming (ROP)
Tricks Whenever you get a file, issuing file command first to it to know what really file is it. Use strings <filename> command to read the strings in the binary to find some clues. Maybe some grep -i command too. Reverse Engineering Tools
Tricks Run checksec check the properties of executable of binary security. You need strong in Assembly Language, computer architecture, C programming (Reverse engineering) and Python language to make script for this challenge! Pwnable Tools
X86-64 Linux Memory Layout Stack Manage local variables Function arguments Control information such as return address Heap Dynamic memory allocation malloc(), calloc(), new() Data Statically allocated data Like global variables, static vars, string constants Text / Shared Libraries Executable machine instructions Read-only Stack Shared Libraries Heap Data Text 0x00007FFFFFFFFFFF 0x0000040000000000 Ref: https://slideplayer.com/slide/14508799/
Memory Allocation Example Ref: https://slideplayer.com/slide/14508799/
Memory Allocation Example l ocal 0x00007ffe4d3be87c p 1 0x00007f7262a1e010 p3 0x00007f7162a1d010 p4 0x000000008359d120 p2 0x000000008359d010 b ig_array 0x0000000080601060 h uge_array 0x0000000000601060 m ain() 0x000000000040060c useless() 0x0000000000400590 Stack Heap Heap Data Text 00007F 000000 Ref: https://slideplayer.com/slide/14508799/
Sample Memory Safety Vulnerability Stack-based buffer overflow Heap-based buffer overflow Format string vulnerability Use after free … Ref: https://cwe.mitre.org/data/definitions/119.html
Breakpoint at 0x4011c8 (return) Analyze before return
Run the program Analyze before return
Control Pointer
0x00000000004011c8 Return address of echo()
Analyze RBP Analyze before return
Overwrite RBP Analyze before return
We do buffer overflow to RBP. Next step How to replace RIP? What address that we want to return? What happened right now? RIP Address (8 bytes) RBP Address (8 bytes) Buf [10]
Overwrite RIP (exit and get in gdb again first) Control Pointer
No one call? Can we call it? Unused function
0x00000000004011da Unused function ( Disassembly )
Data: 0x01020304 Little Endian vs Big Endian Little Endian Big Endian 04 03 02 01 01 02 03 04
Linux: lscpu | grep Endian How to check byte order
r un <<< $(python -c “print ‘A’*18+’\xda\x11\x40’”) 0x4011da -> \xda\x11\x40 Return to smash() function
Please solve this challenge from root-me.org Pwnable Lab
minutes 45
Format String Vulnerability
The Format Function is an ANSI C conversion function. Example function: printf fprintf Converts a primitive variable of the programming language into a human-readable string representation. Format Function
The Format String is the argument of the Format Function and is an ASCII Z string which contains text and format parameters. Example: printf (“The magic number is: %d\n”, 1911); The Format String Parameter , like %x %s defines the type of conversion of the format function. Format String
#include <stdio.h> void main(int argc, char **argv) { // This line is safe printf ("%s\n", argv [1]); // This line is vulnerable printf ( argv [1]); } Vulnerable Code No input validation
Normal Situation
Memory Leaked
Denial of Service
Common parameters used in a Format String Attack
Real Life?
Reverse Engineering
Public Vulnerability
Payload: https://bigip.example.com/iControl/iControlPortal.cgi?WSDL=ASM.LoggingProfile:%08x:%08x:%08x:%08x:%08x:%08x:%08x:%08x Log Result: Nov 29 08:41:47 bigip.example.org soap[4335]: query: WSDL=ASM.LoggingProfile: 0000004c:0000004c:08cb31bc:08cba210:08cc4954:01000000:ffeaa378:f5aa8000 Public Vulnerability
Public Vulnerability
Secure coding perspective Developer need to understand the function that they will use. Web Application Firewall (WAF) You can block the specific message like %s, %x, %p, … Attack Analysis You can analyze common attack parameter like %s, %x, %p, … Pentester You know more technique :D Format String Summary
False Positive (URL Encoding)
Please solve this challenge from root-me.org Pwnable Lab
Summary
https:// c tf101.org [Basic to intermediate ] http://pwnable.kr/ [Basic to advance] https://www.youtube.com/@LiveOverflow [Basic to expert] https://guyinatuxedo.github.io/ [Basic to expert] https://exploit.education/ [Basic to expert] Learning Resources
Tool is just tool!!! Tool could help you, when you have a knowledge. To solve reverse engineering/pwnable CTF you need to learn a lot. Self-learning is the key!!!! Final Thing