-
-
Notifications
You must be signed in to change notification settings - Fork 291
/
Radare2 cheat sheet.txt
162 lines (104 loc) · 4.08 KB
/
Radare2 cheat sheet.txt
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
Commands prefaced by “[0x00000000]>” or “:” are meant to be entered on the r2 cmd prompt, the latter accessed from Visual mode using “:”.
Radare config file
Make a sane config file:
$ vim ~/.radare2rc
e scr.wheel=false #turns off mouse fuckery
e stack.size=114 #increases visible stack size in visual mode
e stack.bytes=false #shows words on stack instead of bytes
Debugging binary with STDIO/Args
Rarun2 config file format for debug target:
$ vim ./binary.rr2
#!/usr/bin/env rarun2
program=binary
stdio=/dev/pts/# #both io to one pty
stdin=/dev/pts/# #just stdin broken out
stdout=/dev/pts/# #just stdout broken out
arg0=”./binary”
arg1=”argument 1”
Terminal config for rarun2 target:
$ tty
/dev/pts/3 #copy this to rarun2 config above
$ clear; sleep 9999999999999999999999999;
Running binary with redirected STDIO via rarun2 + config:
$ r2 -d rarun2 -R ./binary.rr2
Interactive Debugging
Analyze binary for functions, autonaming them:
[0x00000000]> aaa
List found functions and imports:
[0x00000000]> afl
[0x00000000]> afll #long list w/more info
Set breakpoint:
[0x00000000]> db main
[0x00000000]> db 0x400c00
[0x00000000]> db fcn.40e00d
Continue Execution:
[0x00000000]> dc
Continue until next return:
:dcr
Print stack trace:
:dbt
Grepping output:
:pd 200~test #prints next 200 disassembled instructions and searches for ‘test’
Setting lots of breakpoints:
:bp $$ @@=`pd 2000~test`
Visual Mode
Visual mode commands will be represented by [c] where “c” is the key to press while in visual mode. Commands with “:” are entered from command mode, entered with “:” and exited with <enter>.
Enter visual mode:
[0x00000000]> V
Cycle to debug view:
[pp]
Single step-into:
[s]
Single step-over:
[S]
Flag/comment/function view
[_]
* Type to filter for symbol/flag
* <enter> to jump to address
Cursor mode [toggle on/off]
[c]
* <Tab> to Switch view between stack/registers/assembly
* <b> to set breakpoint
* <;> to make a comment on current line\
* <hjkl> to navigate disassembly
XREFs menu:
[x]
* Use when sought to address with XREF
* Displays menu of .text/[other segment] locations which reference current seek address
* Press <enter> to jump to XREF address
Follow jumps/calls (inspect only, not execute):
[enter]
* Current seek address must be at instruction (top line of assembly in Visual mode)
Rename current function:
:afn funcname
Rename current function’s variables:
Base pointer based vars:
:afvb -0x8 name type
* Use -0x# to specify offset from BP
Register based vars:
:afvr reg name type
Save project:
:Ps projectName
Load Project:
:Po projectName
Graph Mode:
[V]
* Must be sought to function’s first address
* Use ‘hjkl’ keys to navigate
* Use +/- to zoom in/out
* Use <Tab>, <t>, <f> to switch focus between blocks and follow jumps
* Use <p> to cycle address/disassembly display
* <q> to quit graph mode
Printing/Inspecting data:
:pxq @ 0x7ffeff4741d8 #print hex quadwords (8-byte) at address
:pxw @ 0x7ffeff4741d8 #print hex doublewords (4-byte) at address
:ps @ rbp - 0x28 #print string at 32-bit pointer
:pS @ [rbp - 0x8] #print string at 64-bit double pointer
:pf qqS @ rsp #print data with format [quad][quad][64b String] at rsp
:drr #reveal register references (telescoping)
Writing Data
Writing data to disk requires launching radare with the write flag [-w] supplied, and cannot be used with debugging [-d] mode. Writing to registers or memory however does not.
:dr eax=rbp-0x8 #write rbp-0x8 to eax register
:wx 9090 @ main+0x10 #write hex bytes @ memory address
:wa test al,al #write assembly at currently sought memory address
https://monosource.gitbooks.io/radare2-explorations/content/intro/navigation.html