one_gadget 1.6.2 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +141 -94
  3. data/bin/one_gadget +4 -3
  4. data/lib/one_gadget/abi.rb +42 -22
  5. data/lib/one_gadget/builds/libc-2.19-397c84e78c14cbffba39a48184db482211df9fb3.rb +38 -0
  6. data/lib/one_gadget/builds/libc-2.19-4eda8ff01be3fba1c7bdd442a8690c3dc7397b6a.rb +44 -0
  7. data/lib/one_gadget/builds/libc-2.19-509ee0c9616c4c3ed81951501a8950e1f529bbff.rb +38 -0
  8. data/lib/one_gadget/builds/libc-2.19-6aff6d091954955fe931bb720a17708513aabda7.rb +41 -0
  9. data/lib/one_gadget/builds/libc-2.19-8d935a42f2f2a1149aa52d3098b32b1d5012cb67.rb +38 -0
  10. data/lib/one_gadget/builds/libc-2.19-a820f849dda0b99ed06dd59bb88404969b3a5f88.rb +41 -0
  11. data/lib/one_gadget/builds/libc-2.19-d9a10b8ef90300628dd0a3a535106967714d7328.rb +47 -0
  12. data/lib/one_gadget/builds/libc-2.21-169a143e9c40cfd9d09695333e45fd67743cd2d6.rb +37 -0
  13. data/lib/one_gadget/builds/libc-2.21-2e9718e58257bda1dc0d751665a3ee233bf606f2.rb +37 -0
  14. data/lib/one_gadget/builds/libc-2.23-29e38445a740bba5a77b86691e3c51a7e48dc79b.rb +46 -0
  15. data/lib/one_gadget/builds/libc-2.23-679ad41a6bc9e718a11a36cf9879cac97197e565.rb +37 -0
  16. data/lib/one_gadget/builds/libc-2.23-b5381a457906d279073822a5ceb24c4bfef94ddb.rb +37 -0
  17. data/lib/one_gadget/builds/libc-2.23-d10fbfd9328f5ffaca50aa93562cb3bfb618fbcc.rb +43 -0
  18. data/lib/one_gadget/builds/libc-2.23-dd5192a769e33ed6ca68a6ab5740ff9e8ec678a7.rb +46 -0
  19. data/lib/one_gadget/builds/libc-2.24-1f7bdfb9a24714835cee6e6597ea7aa782821371.rb +46 -0
  20. data/lib/one_gadget/builds/libc-2.24-206b2bb216b6cdb6b1be565a6fcd29f3862db060.rb +49 -0
  21. data/lib/one_gadget/builds/libc-2.24-26e84118fee5788eb5d8dda66b7e7f029d2c7800.rb +43 -0
  22. data/lib/one_gadget/builds/libc-2.24-43adbb1e7368c94fba1ba9020d8ef0808bff5bc4.rb +37 -0
  23. data/lib/one_gadget/builds/libc-2.24-497931f8d2346a6d0e300a65d8fc6106c6c88c15.rb +37 -0
  24. data/lib/one_gadget/builds/libc-2.24-4fa7401566d6b3e2c7ee5df3b4d85a01f85b595c.rb +37 -0
  25. data/lib/one_gadget/builds/libc-2.24-568d20b7e0d08bc282fb42ae405c7054e4209ede.rb +37 -0
  26. data/lib/one_gadget/builds/libc-2.24-5b72576ff331e93852355123afecdec70fd247b5.rb +49 -0
  27. data/lib/one_gadget/builds/libc-2.24-a4c01d397b6584f7040ef266b16a5d4da0b7a087.rb +43 -0
  28. data/lib/one_gadget/builds/libc-2.24-b81a06f0ac241c4aa8860602d9abcc903adbb675.rb +46 -0
  29. data/lib/one_gadget/builds/libc-2.24-be6d412ecc4816c46eb49e750b02f714a9131c4e.rb +46 -0
  30. data/lib/one_gadget/builds/libc-2.24-d2a8a8ac188a6c3bafa4813a3d2789240ee49489.rb +46 -0
  31. data/lib/one_gadget/builds/libc-2.24-dff06414a29b97b865ef938e06a7751fe8b1b2d0.rb +46 -0
  32. data/lib/one_gadget/builds/libc-2.24-e5dc6c0caa39828fa10ed37e642723a581acdb6d.rb +37 -0
  33. data/lib/one_gadget/builds/libc-2.24-fd0655c4d2073eda4235084e1d0e558f0251be8a.rb +37 -0
  34. data/lib/one_gadget/builds/libc-2.25-e5eb6347f0629b37bf698200022a683b7efb10ed.rb +37 -0
  35. data/lib/one_gadget/builds/libc-2.26-1c39b3b3faa2a2cbb0fa0b6845b29332562262d3.rb +37 -0
  36. data/lib/one_gadget/builds/libc-2.26-499b381aaf00ce85ee5d4a12770ea369b30d2a41.rb +52 -0
  37. data/lib/one_gadget/builds/libc-2.26-4cc84abfe1fd26a485fc2b1b954c281ce9d358fd.rb +52 -0
  38. data/lib/one_gadget/builds/libc-2.26-4ea852c9d6a5084b8b58509b3b3d37d3d8cddb90.rb +52 -0
  39. data/lib/one_gadget/builds/libc-2.26-6d2b609f0c8e7b338f767b08c5ac712fac809d31.rb +49 -0
  40. data/lib/one_gadget/builds/libc-2.26-fb587bc4429e7d1b0de31a3b9ee8ae78ee797eb0.rb +37 -0
  41. data/lib/one_gadget/builds/libc-2.27-0e188ec5f09c187a7a92784d4b97aa251b15a93c.rb +47 -0
  42. data/lib/one_gadget/builds/libc-2.27-53f40c1d2f3739ae017dcdcef1a17314786e3709.rb +38 -0
  43. data/lib/one_gadget/builds/libc-2.27-9dd0bb57f81671704475d1e5163405f7b4d4b454.rb +32 -0
  44. data/lib/one_gadget/builds/libc-2.28-44f5a3efb0e5733fa9d97e690cb36cd4c682bcdb.rb +41 -0
  45. data/lib/one_gadget/builds/libc-2.28-5784a31a1c26f6d2157e585205ebb63dd19ff90f.rb +41 -0
  46. data/lib/one_gadget/builds/libc-2.28-5b157f49586a3ca84d55837f97ff466767dd3445.rb +38 -0
  47. data/lib/one_gadget/builds/libc-2.28-6ee9454b96efa9e343f9e8105f2fa4529265ea05.rb +38 -0
  48. data/lib/one_gadget/emulators/aarch64.rb +176 -0
  49. data/lib/one_gadget/emulators/amd64.rb +1 -1
  50. data/lib/one_gadget/emulators/i386.rb +1 -1
  51. data/lib/one_gadget/emulators/instruction.rb +36 -7
  52. data/lib/one_gadget/emulators/lambda.rb +36 -25
  53. data/lib/one_gadget/emulators/processor.rb +94 -6
  54. data/lib/one_gadget/emulators/x86.rb +43 -95
  55. data/lib/one_gadget/error.rb +15 -3
  56. data/lib/one_gadget/fetcher.rb +3 -1
  57. data/lib/one_gadget/fetchers/aarch64.rb +41 -0
  58. data/lib/one_gadget/fetchers/amd64.rb +4 -2
  59. data/lib/one_gadget/fetchers/base.rb +35 -11
  60. data/lib/one_gadget/fetchers/i386.rb +2 -2
  61. data/lib/one_gadget/fetchers/x86.rb +23 -0
  62. data/lib/one_gadget/gadget.rb +63 -11
  63. data/lib/one_gadget/helper.rb +282 -203
  64. data/lib/one_gadget/one_gadget.rb +12 -4
  65. data/lib/one_gadget/version.rb +1 -1
  66. metadata +57 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e26da79b62658e7dd1ce9efcaeda04fbe805b98eb1fecf234948311d70553e3
4
- data.tar.gz: 2ed832df9cffecaba987753e1ed9c9ebe8068e410c00da108c1348e80efe6637
3
+ metadata.gz: cb3e8709a50b2ef22f37f074e9c9d2da21e208bbf71a0679966bd461728adef7
4
+ data.tar.gz: 98351653ab6b1207acb3e71fc59c6a7de60b5b9de2255f582963e37d40dcf6c4
5
5
  SHA512:
6
- metadata.gz: 47732f230a683edcb699a21f3891812326b1a7d9b966c13fb3a50c8d07b7ffbb3ce4244d324c0f13907f8b5d64e6a16a824d44946d97f6f131df7cf0b1380b8e
7
- data.tar.gz: 0a90f8f323ee47f78314eeb420eec22a36f8954b12806a47d493d8996128abb4ac40c2cb4ec25b236b3723a390391903e5082f1af6751a061645e4dfc442e8e0
6
+ metadata.gz: 91f45537678c2a257cdba8870d347396e65deb407fc8173a48c6a2475422b6575bf07b624223dbf5c1381935cdd384fc79a1e334d5fa4c8179f084f7b8da4a52
7
+ data.tar.gz: 3a79932b8b1c304786a486769544bec8ee2f11b8147e7cb694e8d0b2a9391df1dc1fc2fe2f182f46c23ac2ab2ae05c2f128d93f580a83c7f6be567e7d8f1a786
data/README.md CHANGED
@@ -6,41 +6,38 @@
6
6
  [![Inline docs](https://inch-ci.org/github/david942j/one_gadget.svg?branch=master)](https://inch-ci.org/github/david942j/one_gadget)
7
7
  [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](http://choosealicense.com/licenses/mit/)
8
8
 
9
- ## One Gadget
9
+ ## OneGadget
10
10
 
11
11
  When playing ctf pwn challenges we usually need the one-gadget RCE (remote code execution),
12
12
  which leads to call `execve('/bin/sh', NULL, NULL)`.
13
13
 
14
14
  This gem provides such gadgets finder, no need to use objdump or IDA-pro every time like a fool :wink:
15
15
 
16
- To use this tool, just type `one_gadget /path/to/libc` in command line and enjoy the magic :laughing:
16
+ To use this tool, type `one_gadget /path/to/libc` in command line and enjoy the magic :laughing:
17
17
 
18
- Note: Supports amd64 and i386!
19
-
20
- ## Install
18
+ ## Installation
21
19
 
22
20
  Available on RubyGems.org!
23
21
  ```bash
24
22
  $ gem install one_gadget
25
23
  ```
26
24
 
27
- Note: require ruby version >= 2.1.0, you can use `ruby --version` to check.
25
+ Note: requires ruby version >= 2.1.0, you can use `ruby --version` to check.
26
+
27
+ ## Supported Architectures
28
+
29
+ - [x] i386
30
+ - [x] amd64 (x86-64)
31
+ - [x] aarch64 (ARMv8)
28
32
 
29
33
  ## Implementation
30
34
 
31
- OneGadget uses simple self-implement symbolic execution to find the constraints of gadgets to be successful.
35
+ OneGadget uses symbolic execution to find the constraints of gadgets to be successful.
32
36
 
33
- The article introducing how I develop this tool can be found [in my blog](https://david942j.blogspot.com/2017/02/project-one-gadget-in-glibc.html).
37
+ The article introducing how I develop this tool can be found [on my blog](https://david942j.blogspot.com/2017/02/project-one-gadget-in-glibc.html).
34
38
 
35
39
  ## Usage
36
40
 
37
- Since OneGadget version 1.5.0,
38
- much more one-gadgets have been found.
39
- And gadgets become too many to show them all,
40
- they would be selected automatically according to the difficulty of constraints.
41
- Therefore, gadgets shown will be less than previous versions (before v1.5.0).
42
- But you can use option `--level 1` to show all gadgets found.
43
-
44
41
  ### Command Line Interface
45
42
 
46
43
  ```bash
@@ -58,117 +55,169 @@ $ one_gadget
58
55
  # --info BuildID Show version information given BuildID.
59
56
  # --version Current gem version.
60
57
 
61
- $ one_gadget -b 60131540dadc6796cab33388349e6e4e68692053
62
- # 0x45216 execve("/bin/sh", rsp+0x30, environ)
58
+ ```
59
+
60
+ ```bash
61
+ $ one_gadget /lib/x86_64-linux-gnu/libc.so.6
62
+ # 0x4f2c5 execve("/bin/sh", rsp+0x40, environ)
63
+ # constraints:
64
+ # rcx == NULL
65
+ #
66
+ # 0x4f322 execve("/bin/sh", rsp+0x40, environ)
67
+ # constraints:
68
+ # [rsp+0x40] == NULL
69
+ #
70
+ # 0x10a38c execve("/bin/sh", rsp+0x70, environ)
71
+ # constraints:
72
+ # [rsp+0x70] == NULL
73
+
74
+ ```
75
+ ![x86_64](https://github.com/david942j/one_gadget/blob/master/examples/x86_64.png?raw=true)
76
+
77
+ #### Given BuildID
78
+ ```bash
79
+ $ one_gadget -b aad7dbe330f23ea00ca63daf793b766b51aceb5d
80
+ # 0x45526 execve("/bin/sh", rsp+0x30, environ)
63
81
  # constraints:
64
82
  # rax == NULL
65
83
  #
66
- # 0x4526a execve("/bin/sh", rsp+0x30, environ)
84
+ # 0x4557a execve("/bin/sh", rsp+0x30, environ)
67
85
  # constraints:
68
86
  # [rsp+0x30] == NULL
69
87
  #
70
- # 0xef6c4 execve("/bin/sh", rsp+0x50, environ)
88
+ # 0xf1651 execve("/bin/sh", rsp+0x40, environ)
71
89
  # constraints:
72
- # [rsp+0x50] == NULL
90
+ # [rsp+0x40] == NULL
73
91
  #
74
- # 0xf0567 execve("/bin/sh", rsp+0x70, environ)
92
+ # 0xf24cb execve("/bin/sh", rsp+0x60, environ)
75
93
  # constraints:
76
- # [rsp+0x70] == NULL
94
+ # [rsp+0x60] == NULL
77
95
 
78
- $ one_gadget /lib32/libc.so.6
79
- # 0x3a7cc execve("/bin/sh", esp+0x28, environ)
96
+ ```
97
+ ![build id](https://github.com/david942j/one_gadget/blob/master/examples/from_build_id.png?raw=true)
98
+
99
+ #### Show All Gadgets
100
+
101
+ Sometimes `one_gadget` finds too many gadgets to show them in one screen,
102
+ by default gadgets would be filtered automatically *according to the difficulty of constraints*.
103
+
104
+ Use option `--level 1` to show all gadgets found instead of only those with higher probabilities.
105
+
106
+ ```bash
107
+ $ one_gadget /lib/x86_64-linux-gnu/libc.so.6 --level 1
108
+ # 0x4f2c5 execve("/bin/sh", rsp+0x40, environ)
80
109
  # constraints:
81
- # esi is the GOT address of libc
82
- # [esp+0x28] == NULL
110
+ # rcx == NULL
83
111
  #
84
- # 0x3a7ce execve("/bin/sh", esp+0x2c, environ)
112
+ # 0x4f322 execve("/bin/sh", rsp+0x40, environ)
85
113
  # constraints:
86
- # esi is the GOT address of libc
87
- # [esp+0x2c] == NULL
114
+ # [rsp+0x40] == NULL
88
115
  #
89
- # 0x3a7d2 execve("/bin/sh", esp+0x30, environ)
116
+ # 0xe569f execve("/bin/sh", r14, r12)
90
117
  # constraints:
91
- # esi is the GOT address of libc
92
- # [esp+0x30] == NULL
118
+ # [r14] == NULL || r14 == NULL
119
+ # [r12] == NULL || r12 == NULL
93
120
  #
94
- # 0x3a7d9 execve("/bin/sh", esp+0x34, environ)
121
+ # 0xe5858 execve("/bin/sh", [rbp-0x88], [rbp-0x70])
95
122
  # constraints:
96
- # esi is the GOT address of libc
97
- # [esp+0x34] == NULL
123
+ # [[rbp-0x88]] == NULL || [rbp-0x88] == NULL
124
+ # [[rbp-0x70]] == NULL || [rbp-0x70] == NULL
98
125
  #
99
- # 0x5f875 execl("/bin/sh", eax)
126
+ # 0xe585f execve("/bin/sh", r10, [rbp-0x70])
100
127
  # constraints:
101
- # esi is the GOT address of libc
102
- # eax == NULL
128
+ # [r10] == NULL || r10 == NULL
129
+ # [[rbp-0x70]] == NULL || [rbp-0x70] == NULL
103
130
  #
104
- # 0x5f876 execl("/bin/sh", [esp])
131
+ # 0xe5863 execve("/bin/sh", r10, rdx)
105
132
  # constraints:
106
- # esi is the GOT address of libc
107
- # [esp] == NULL
108
-
109
- $ one_gadget /lib/x86_64-linux-gnu/libc.so.6
110
- # 0x45526 execve("/bin/sh", rsp+0x30, environ)
111
- # constraints:
112
- # rax == NULL
133
+ # [r10] == NULL || r10 == NULL
134
+ # [rdx] == NULL || rdx == NULL
113
135
  #
114
- # 0x4557a execve("/bin/sh", rsp+0x30, environ)
136
+ # 0x10a38c execve("/bin/sh", rsp+0x70, environ)
115
137
  # constraints:
116
- # [rsp+0x30] == NULL
138
+ # [rsp+0x70] == NULL
117
139
  #
118
- # 0xf1651 execve("/bin/sh", rsp+0x40, environ)
140
+ # 0x10a398 execve("/bin/sh", rsi, [rax])
119
141
  # constraints:
120
- # [rsp+0x40] == NULL
142
+ # [rsi] == NULL || rsi == NULL
143
+ # [[rax]] == NULL || [rax] == NULL
144
+
145
+ ```
146
+
147
+ #### Other Architectures
148
+
149
+ ##### i386
150
+ ```bash
151
+ $ one_gadget /lib32/libc.so.6
152
+ # 0x3cbea execve("/bin/sh", esp+0x34, environ)
153
+ # constraints:
154
+ # esi is the GOT address of libc
155
+ # [esp+0x34] == NULL
121
156
  #
122
- # 0xf24cb execve("/bin/sh", rsp+0x60, environ)
157
+ # 0x3cbec execve("/bin/sh", esp+0x38, environ)
123
158
  # constraints:
124
- # [rsp+0x60] == NULL
125
-
126
- # show all gadgets found
127
- $ one_gadget /lib/x86_64-linux-gnu/libc.so.6 --level 1
128
- # 0x45526 execve("/bin/sh", rsp+0x30, environ)
159
+ # esi is the GOT address of libc
160
+ # [esp+0x38] == NULL
161
+ #
162
+ # 0x3cbf0 execve("/bin/sh", esp+0x3c, environ)
129
163
  # constraints:
130
- # rax == NULL
164
+ # esi is the GOT address of libc
165
+ # [esp+0x3c] == NULL
131
166
  #
132
- # 0x4557a execve("/bin/sh", rsp+0x30, environ)
167
+ # 0x3cbf7 execve("/bin/sh", esp+0x40, environ)
133
168
  # constraints:
134
- # [rsp+0x30] == NULL
169
+ # esi is the GOT address of libc
170
+ # [esp+0x40] == NULL
135
171
  #
136
- # 0xcde41 execve("/bin/sh", r15, r13)
172
+ # 0x6729f execl("/bin/sh", eax)
137
173
  # constraints:
138
- # [r15] == NULL || r15 == NULL
139
- # [r13] == NULL || r13 == NULL
174
+ # esi is the GOT address of libc
175
+ # eax == NULL
140
176
  #
141
- # 0xce0e1 execve("/bin/sh", [rbp-0x78], [rbp-0x50])
177
+ # 0x672a0 execl("/bin/sh", [esp])
142
178
  # constraints:
143
- # [[rbp-0x78]] == NULL || [rbp-0x78] == NULL
144
- # [[rbp-0x50]] == NULL || [rbp-0x50] == NULL
179
+ # esi is the GOT address of libc
180
+ # [esp] == NULL
145
181
  #
146
- # 0xce0e5 execve("/bin/sh", r9, [rbp-0x50])
182
+ # 0x13573e execl("/bin/sh", eax)
147
183
  # constraints:
148
- # [r9] == NULL || r9 == NULL
149
- # [[rbp-0x50]] == NULL || [rbp-0x50] == NULL
184
+ # ebx is the GOT address of libc
185
+ # eax == NULL
150
186
  #
151
- # 0xce0e9 execve("/bin/sh", r9, rdx)
187
+ # 0x13573f execl("/bin/sh", [esp])
152
188
  # constraints:
153
- # [r9] == NULL || r9 == NULL
154
- # [rdx] == NULL || rdx == NULL
189
+ # ebx is the GOT address of libc
190
+ # [esp] == NULL
191
+
192
+ ```
193
+ ![i386](https://github.com/david942j/one_gadget/blob/master/examples/i386.png?raw=true)
194
+
195
+ ##### AArch64
196
+ ```bash
197
+ $ one_gadget spec/data/aarch64-libc-2.27.so
198
+ # 0x3f160 execve("/bin/sh", sp+0x70, environ)
199
+ # constraints:
200
+ # address x20+0x338 is writable
201
+ # x3 == NULL
155
202
  #
156
- # 0xf1651 execve("/bin/sh", rsp+0x40, environ)
203
+ # 0x3f184 execve("/bin/sh", sp+0x70, environ)
157
204
  # constraints:
158
- # [rsp+0x40] == NULL
205
+ # addresses x19+0x4, x20+0x338 are writable
206
+ # [sp+0x70] == NULL
159
207
  #
160
- # 0xf165d execve("/bin/sh", rsi, [rax])
208
+ # 0x3f1a8 execve("/bin/sh", x21, environ)
161
209
  # constraints:
162
- # [rsi] == NULL || rsi == NULL
163
- # [[rax]] == NULL || [rax] == NULL
210
+ # addresses x19+0x4, x20+0x338 are writable
211
+ # [x21] == NULL || x21 == NULL
164
212
  #
165
- # 0xf24cb execve("/bin/sh", rsp+0x60, environ)
213
+ # 0x63e90 execl("/bin/sh", x1)
166
214
  # constraints:
167
- # [rsp+0x60] == NULL
215
+ # x1 == NULL
168
216
 
169
217
  ```
218
+ ![aarch64](https://github.com/david942j/one_gadget/blob/master/examples/aarch64.png?raw=true)
170
219
 
171
- #### Combine with exploit script
220
+ #### Combine with Script
172
221
  Pass your exploit script as `one_gadget`'s arguments, it can
173
222
  try all gadgets one by one, so you don't need to try every possible gadgets manually.
174
223
 
@@ -178,34 +227,32 @@ $ one_gadget ./spec/data/libc-2.19.so -s 'echo "offset ->"'
178
227
 
179
228
  ![--script](https://github.com/david942j/one_gadget/blob/master/examples/script.png?raw=true)
180
229
 
181
- ### Directly use in script
230
+ ### In Ruby Scripts
182
231
  ```ruby
183
232
  require 'one_gadget'
184
233
  OneGadget.gadgets(file: '/lib/x86_64-linux-gnu/libc.so.6')
185
- #=> [283942, 284026, 988753, 992459]
234
+ #=> [324293, 324386, 1090444]
186
235
 
187
236
  # or in shorter way
188
237
  one_gadget('/lib/x86_64-linux-gnu/libc.so.6', level: 1)
189
- #=> [283942, 284026, 843329, 844001, 844005, 844009, 988753, 988765, 992459]
238
+ #=> [324293, 324386, 939679, 940120, 940127, 940131, 1090444, 1090456]
190
239
 
191
240
  # from build id
192
- one_gadget('60131540dadc6796cab33388349e6e4e68692053')
193
- #=> [283158, 283242, 980676, 984423]
241
+ one_gadget('b417c0ba7cc5cf06d1d1bed6652cedb9253c60d0')
242
+ #=> [324293, 324386, 1090444]
194
243
 
195
244
  ```
196
245
 
197
- ## Screenshots
198
-
199
- ### Search gadgets in libc
200
-
201
- #### 64 bit
202
- ![from file](https://github.com/david942j/one_gadget/blob/master/examples/from_file.png?raw=true)
246
+ ### To Python Lovers
247
+ ```python
248
+ import subprocess
249
+ def one_gadget(filename):
250
+ return map(int, subprocess.check_output(['one_gadget', '--raw', filename]).split(' '))
203
251
 
204
- #### 32 bit
205
- ![from file](https://github.com/david942j/one_gadget/blob/master/examples/from_file_32bit.png?raw=true)
252
+ one_gadget('/lib/x86_64-linux-gnu/libc.so.6')
253
+ #=> [324293, 324386, 1090444]
206
254
 
207
- ### Fetch gadgets from database
208
- ![build id](https://github.com/david942j/one_gadget/blob/master/examples/from_build_id.png?raw=true)
255
+ ```
209
256
 
210
257
  ## Make OneGadget Better
211
258
  Any suggestion or feature request is welcome! Feel free to send a pull request.
data/bin/one_gadget CHANGED
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
- require 'one_gadget'
2
+
3
3
  require 'optparse'
4
4
 
5
+ require 'one_gadget'
6
+
5
7
  options = { raw: false }
6
8
  usage = 'Usage: one_gadget [file] [options]'
7
9
  parser = OptionParser.new do |opts|
@@ -70,10 +72,9 @@ else
70
72
  exit(1)
71
73
  end
72
74
 
73
- extend OneGadget::Helper::ClassMethods
74
75
  if options[:script]
75
76
  gadgets.map(&:offset).each do |offset|
76
- OneGadget::Logger.info("Trying #{colorize(format('0x%x', offset), sev: :integer)}...\n")
77
+ OneGadget::Logger.info("Trying #{OneGadget::Helper.colorize(format('0x%x', offset), sev: :integer)}...\n")
77
78
  execute(options[:script], offset)
78
79
  end
79
80
  exit(0)
@@ -1,29 +1,49 @@
1
1
  module OneGadget
2
- # define the abi of different architecture.
2
+ # Defines the abi of different architectures.
3
3
  module ABI
4
- # Define class methods here.
5
- module ClassMethods
6
- # Registers in i386.
7
- LINUX_X86_32 = %w(eax ebx ecx edx edi esi ebp esp) + 0.upto(7).map { |i| "xmm#{i}" }
8
- # Registers in x86_64/
9
- LINUX_X86_64 = LINUX_X86_32 +
10
- %w(rax rbx rcx rdx rdi rsi rbp rsp) +
11
- 8.upto(15).map { |i| "r#{i}" } +
12
- 8.upto(15).map { |i| "xmm#{i}" }
13
- # Registers' name in amd64.
14
- # @return [Array<String>] List of registers.
15
- def amd64
16
- LINUX_X86_64
17
- end
4
+ # Registers of i386.
5
+ X86_32 = %w[eax ebx ecx edx edi esi ebp esp] + 0.upto(7).map { |i| "xmm#{i}" }
6
+ # Registers of x86_64.
7
+ X86_64 = X86_32 +
8
+ %w[rax rbx rcx rdx rdi rsi rbp rsp] +
9
+ 8.upto(15).map { |i| "r#{i}" } +
10
+ 8.upto(15).map { |i| "xmm#{i}" }
18
11
 
19
- # Registers' name in i386.
20
- # @return [Array<String>] List of registers.
21
- def i386
22
- LINUX_X86_32
23
- end
12
+ # Registers of AArch64.
13
+ AARCH64 = %w[xzr wzr sp] + 0.upto(30).map { |i| ["x#{i}", "w#{i}"] }.flatten
24
14
 
25
- alias all amd64
15
+ module_function
16
+
17
+ # Registers' name of amd64.
18
+ # @return [Array<String>] List of registers.
19
+ def amd64
20
+ X86_64.uniq
21
+ end
22
+
23
+ # Registers' name of i386.
24
+ # @return [Array<String>] List of registers.
25
+ def i386
26
+ X86_32
27
+ end
28
+
29
+ # Registers' name of aarch64.
30
+ # @return [Array<String>] List of registers.
31
+ def aarch64
32
+ AARCH64
33
+ end
34
+
35
+ # Returns all names of registers.
36
+ # @return [Array<String>] List of registers.
37
+ def all
38
+ amd64 + aarch64
39
+ end
40
+
41
+ # Checks if the register is a stack-related pointer.
42
+ # @param [String] reg
43
+ # Register's name.
44
+ # @return [Boolean]
45
+ def stack_register?(reg)
46
+ %w[esp ebp rsp rbp sp x29].include?(reg)
26
47
  end
27
- extend ClassMethods
28
48
  end
29
49
  end
@@ -0,0 +1,38 @@
1
+ require 'one_gadget/gadget'
2
+ # https://gitlab.com/libcdb/libcdb/blob/master/libc/libc6_2.19-10ubuntu2_arm64/lib/aarch64-linux-gnu/libc-2.19.so
3
+ #
4
+ # AArch64
5
+ #
6
+ # GNU C Library (Ubuntu GLIBC 2.19-10ubuntu2) stable release version 2.19, by Roland McGrath et al.
7
+ # Copyright (C) 2014 Free Software Foundation, Inc.
8
+ # This is free software; see the source for copying conditions.
9
+ # There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
10
+ # PARTICULAR PURPOSE.
11
+ # Compiled by GNU CC version 4.8.3.
12
+ # Compiled on a Linux 3.16.3 system on 2014-09-30.
13
+ # Available extensions:
14
+ # crypt add-on version 2.1 by Michael Glad and others
15
+ # GNU Libidn by Simon Josefsson
16
+ # Native POSIX Threads Library by Ulrich Drepper et al
17
+ # BIND-8.2.3-T5B
18
+ # libc ABIs: UNIQUE
19
+ # For bug reporting instructions, please see:
20
+ # <https://bugs.launchpad.net/ubuntu/+source/glibc/+bugs>.
21
+
22
+ build_id = File.basename(__FILE__, '.rb').split('-').last
23
+ OneGadget::Gadget.add(build_id, 261724,
24
+ constraints: ["writable: x21+0x2e0", "x3+0x9e0 == NULL"],
25
+ effect: "execve(\"/bin/sh\", sp+0x68, environ)")
26
+ OneGadget::Gadget.add(build_id, 261732,
27
+ constraints: ["writable: x20", "writable: x21+0x2e0", "[x20] == NULL || x20 == NULL"],
28
+ effect: "execve(\"/bin/sh\", x20, environ)")
29
+ OneGadget::Gadget.add(build_id, 261808,
30
+ constraints: ["writable: x21+0x2e0", "writable: x24+0x4", "[x20] == NULL || x20 == NULL"],
31
+ effect: "execve(\"/bin/sh\", x20, environ)")
32
+ OneGadget::Gadget.add(build_id, 261820,
33
+ constraints: ["writable: x21+0x2e0", "writable: x24+0x4", "[x1] == NULL || x1 == NULL", "[[x0]] == NULL || [x0] == NULL"],
34
+ effect: "execve(\"/bin/sh\", x1, [x0])")
35
+ OneGadget::Gadget.add(build_id, 261824,
36
+ constraints: ["writable: x21+0x2e0", "writable: x24+0x4", "[x1] == NULL || x1 == NULL", "[x2] == NULL || x2 == NULL"],
37
+ effect: "execve(\"/bin/sh\", x1, x2)")
38
+