pymwemu 0.9.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. pymwemu-0.9.3/PKG-INFO +271 -0
  2. pymwemu-0.9.3/pymwemu/.gitignore +73 -0
  3. pymwemu-0.9.3/pymwemu/Cargo.lock +893 -0
  4. pymwemu-0.9.3/pymwemu/Cargo.toml +16 -0
  5. pymwemu-0.9.3/pymwemu/DOCUMENTATION.md +490 -0
  6. pymwemu-0.9.3/pymwemu/README.md +260 -0
  7. pymwemu-0.9.3/pymwemu/examples/danabot_rsa.ipynb +86 -0
  8. pymwemu-0.9.3/pymwemu/examples/raccoon_strings.ipynb +253 -0
  9. pymwemu-0.9.3/pymwemu/examples/scripts/.ipynb_checkpoints/test-checkpoint.py +0 -0
  10. pymwemu-0.9.3/pymwemu/examples/scripts/api_implementation.py +37 -0
  11. pymwemu-0.9.3/pymwemu/examples/scripts/danabot_crypto.py +30 -0
  12. pymwemu-0.9.3/pymwemu/examples/scripts/danabot_extract.py +34 -0
  13. pymwemu-0.9.3/pymwemu/examples/scripts/danabot_get_string_emu.py +24 -0
  14. pymwemu-0.9.3/pymwemu/examples/scripts/danabot_int_deobfus_emu.py +14 -0
  15. pymwemu-0.9.3/pymwemu/examples/scripts/emu_pwer.py +29 -0
  16. pymwemu-0.9.3/pymwemu/examples/scripts/emu_rat.py +64 -0
  17. pymwemu-0.9.3/pymwemu/examples/scripts/gozi_decryptbss_emu.py +63 -0
  18. pymwemu-0.9.3/pymwemu/examples/scripts/gozi_dga.py +23 -0
  19. pymwemu-0.9.3/pymwemu/examples/scripts/raccoon_strings.py +36 -0
  20. pymwemu-0.9.3/pymwemu/examples/scripts/ssl_key128_gen.py +32 -0
  21. pymwemu-0.9.3/pymwemu/examples/scripts/test.py +35 -0
  22. pymwemu-0.9.3/pymwemu/examples/scripts/vidar_strings.py +27 -0
  23. pymwemu-0.9.3/pymwemu/examples/scripts/vidar_strings2.py +16 -0
  24. pymwemu-0.9.3/pymwemu/examples/scripts/xloader_dexor.py +25 -0
  25. pymwemu-0.9.3/pymwemu/examples/scripts/xloader_keygen.py +24 -0
  26. pymwemu-0.9.3/pymwemu/examples/xloader_keygen.ipynb +81 -0
  27. pymwemu-0.9.3/pymwemu/src/lib.rs +857 -0
  28. pymwemu-0.9.3/pyproject.toml +21 -0
pymwemu-0.9.3/PKG-INFO ADDED
@@ -0,0 +1,271 @@
1
+ Metadata-Version: 2.4
2
+ Name: pymwemu
3
+ Version: 0.9.3
4
+ Classifier: Programming Language :: Rust
5
+ Classifier: Programming Language :: Python :: Implementation :: CPython
6
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
7
+ Summary: x86 32/64bits and system internals emulator, for securely emulating malware and other stuff.
8
+ Requires-Python: >=3.7
9
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
10
+
11
+ # PYMWEMU
12
+
13
+ ## Examples
14
+
15
+ https://github.com/sha0coder/pymwemu/tree/main/examples
16
+
17
+ ## Documentation
18
+
19
+ https://github.com/sha0coder/pymwemu/blob/main/DOCUMENTATION.md
20
+
21
+ ## Gpt Assistant
22
+
23
+ https://chat.openai.com/g/g-sfrh5tzEM-pymwemu-helper
24
+
25
+ ## Install
26
+ ```bash
27
+ pip install --upgrade pip
28
+ pip3 install --upgrade pip
29
+ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
30
+ pip install pymwemu
31
+ pip3 install pymwemu
32
+ ```
33
+
34
+ ## Mac Install
35
+ same procedure, if there is a problem with !tapi-tbd the solution is:
36
+ ```bash
37
+ sudo xcode-select --switch /Library/Developer/CommandLineTools
38
+ ```
39
+
40
+ ## Download maps
41
+ download maps32 from releases or maps64 better from git:
42
+ https://github.com/sha0coder/mwemu
43
+
44
+ releases:
45
+
46
+ https://github.com/sha0coder/mwemu/releases/download/maps/maps32.zip
47
+ https://github.com/sha0coder/mwemu/releases/download/maps/maps64.zip
48
+
49
+
50
+ ## Usage
51
+
52
+ ### Fully emulation of a shellcode
53
+
54
+ ```python
55
+ ~ ❯❯❯ python3
56
+ Python 3.9.2 (default, Feb 28 2021, 17:03:44)
57
+ [GCC 10.2.1 20210110] on linux
58
+ Type "help", "copyright", "credits" or "license" for more information.
59
+ >>> import pymwemu
60
+ >>> emu = pymwemu.init32()
61
+ >>> emu.load_maps('/home/sha0/src/mwemu/maps32/')
62
+ initializing regs
63
+ loading memory maps
64
+ Loaded nsi.dll
65
+ 4 sections base addr 0x776c0000
66
+ created pe32 map for section `.text` at 0x776c1000 size: 5624
67
+ created pe32 map for section `.data` at 0x776c3000 size: 16
68
+ created pe32 map for section `.rsrc` at 0x776c4000 size: 1008
69
+ /!\ warning: raw sz:8704 off:8192 sz:512 off+sz:8704
70
+ created pe32 map for section `.reloc` at 0x776c5000 size: 88
71
+ >>>
72
+ >>> emu.load_binary('/home/sha0/src/mwemu/shellcodes32/shikata.bin')
73
+ shellcode detected.
74
+ >>> emu.set_verbose(0) # by default already 0
75
+ >>> emu.disable_console() # by default already disabled
76
+ >>> emu.run() #
77
+ ----- emulation -----
78
+ ** 333368 kernel32!LoadLibraryA 'ws2_32' =0x77480000
79
+ ** 1618021 ws2_32!WsaStartup
80
+ ** 2902832 ws2_32!WsaSocketA
81
+ ** 4180546 ws2_32!connect family: 2 192.168.1.38:1337
82
+ ** 5456468 ws2_32!recv buff: 0x22de64 sz: 4
83
+ ** 5736281 kernel32!VirtualAlloc sz: 256 addr: 0x164
84
+ ** 7012203 ws2_32!recv buff: 0x164 sz: 256
85
+ redirecting code flow to non maped address 0x264
86
+
87
+ >>> help(emu.run)
88
+ Help on built-in function run:
89
+
90
+ run(end_addr) method of builtins.Emu instance
91
+ start emulating the binary until reach the provided end_addr.
92
+ Use run() with no param for emulating forever.
93
+ ```
94
+
95
+
96
+ ### Loading Danabot PE
97
+
98
+ ```python
99
+ >>> emu.load_binary('/home/sha0/samples/danabot/2023-04-03-MainModule/unpacked2/dbmm_unpacked.dll')
100
+ PE32 header detected.
101
+ IAT binding started ...
102
+ Loaded /home/sha0/src/mwemu/maps32/version.dll
103
+ 5 sections base addr 0x52180000
104
+ created pe32 map for section `.text` at 0x52181000 size: 10431
105
+ created pe32 map for section `.data` at 0x52184000 size: 872
106
+ created pe32 map for section `.idata` at 0x52185000 size: 3176
107
+ created pe32 map for section `.rsrc` at 0x52186000 size: 1064
108
+ created pe32 map for section `.reloc` at 0x52187000 size: 820
109
+ Loaded /home/sha0/src/mwemu/maps32/mpr.dll
110
+ 6 sections base addr 0x4b680000
111
+ created pe32 map for section `.text` at 0x4b681000 size: 71344
112
+ created pe32 map for section `.data` at 0x4b693000 size: 1260
113
+ created pe32 map for section `.idata` at 0x4b694000 size: 4228
114
+ created pe32 map for section `.didat` at 0x4b696000 size: 80
115
+ created pe32 map for section `.rsrc` at 0x4b697000 size: 1296
116
+ created pe32 map for section `.reloc` at 0x4b698000 size: 3856
117
+ Loaded /home/sha0/src/mwemu/maps32/netapi32.dll
118
+ 4 sections base addr 0x40ac0000
119
+ created pe32 map for section `.text` at 0x40ac1000 size: 51905
120
+ created pe32 map for section `.data` at 0x40ace000 size: 992
121
+ created pe32 map for section `.rsrc` at 0x40acf000 size: 1016
122
+ /!\ warning: raw sz:56832 off:55808 sz:1024 off+sz:56832
123
+ created pe32 map for section `.reloc` at 0x40ad0000 size: 908
124
+ Loaded /home/sha0/src/mwemu/maps32/shell32.dll
125
+ 4 sections base addr 0x73800000
126
+ created pe32 map for section `.text` at 0x73801000 size: 3966180
127
+ created pe32 map for section `.data` at 0x73bca000 size: 26872
128
+ created pe32 map for section `.rsrc` at 0x73bd1000 size: 8670296
129
+ /!\ warning: raw sz:12872192 off:12660736 sz:211456 off+sz:12872192
130
+ created pe32 map for section `.reloc` at 0x74416000 size: 211060
131
+ Loaded /home/sha0/src/mwemu/maps32/esent.dll
132
+ 7 sections base addr 0x10000000
133
+ created pe32 map for section `.text` at 0x10001000 size: 2573914
134
+ created pe32 map for section `.data` at 0x10276000 size: 22056
135
+ created pe32 map for section `.idata` at 0x1027c000 size: 7442
136
+ created pe32 map for section `.didat` at 0x1027e000 size: 44
137
+ created pe32 map for section `cachelin` at 0x1027f000 size: 1824
138
+ created pe32 map for section `.rsrc` at 0x10280000 size: 1360
139
+ /!\ warning: raw sz:2712064 off:2597376 sz:114688 off+sz:2712064
140
+ created pe32 map for section `.reloc` at 0x10281000 size: 114200
141
+ Loaded /home/sha0/src/mwemu/maps32/iphlpapi.dll
142
+ 4 sections base addr 0x40c90000
143
+ created pe32 map for section `.text` at 0x40c91000 size: 96173
144
+ created pe32 map for section `.data` at 0x40ca9000 size: 1936
145
+ created pe32 map for section `.rsrc` at 0x40caa000 size: 1288
146
+ /!\ warning: raw sz:103936 off:101376 sz:2560 off+sz:103936
147
+ created pe32 map for section `.reloc` at 0x40cab000 size: 2372
148
+ Loaded /home/sha0/src/mwemu/maps32/winspool.drv.dll
149
+ 6 sections base addr 0x4cc80000
150
+ created pe32 map for section `.text` at 0x4cc81000 size: 328345
151
+ created pe32 map for section `.data` at 0x4ccd2000 size: 4972
152
+ created pe32 map for section `.idata` at 0x4ccd4000 size: 8628
153
+ created pe32 map for section `.didat` at 0x4ccd7000 size: 548
154
+ created pe32 map for section `.rsrc` at 0x4ccd8000 size: 88632
155
+ /!\ warning: raw sz:449536 off:430080 sz:19456 off+sz:449536
156
+ created pe32 map for section `.reloc` at 0x4ccee000 size: 19448
157
+ Loaded /home/sha0/src/mwemu/maps32/netapi32.dll
158
+ 4 sections base addr 0x40ac0000
159
+ created pe32 map for section `.text` at 0x40ac1000 size: 51905
160
+ created pe32 map for section `.data` at 0x40ace000 size: 992
161
+ created pe32 map for section `.rsrc` at 0x40acf000 size: 1016
162
+ /!\ warning: raw sz:56832 off:55808 sz:1024 off+sz:56832
163
+ created pe32 map for section `.reloc` at 0x40ad0000 size: 908
164
+ Loaded /home/sha0/src/mwemu/maps32/rasapi32.dll
165
+ 6 sections base addr 0x10000000
166
+ created pe32 map for section `.text` at 0x10001000 size: 812208
167
+ created pe32 map for section `.data` at 0x100c8000 size: 5692
168
+ created pe32 map for section `.idata` at 0x100ca000 size: 9484
169
+ created pe32 map for section `.didat` at 0x100cd000 size: 524
170
+ created pe32 map for section `.rsrc` at 0x100ce000 size: 1296
171
+ /!\ warning: raw sz:875008 off:826880 sz:48128 off+sz:875008
172
+ created pe32 map for section `.reloc` at 0x100cf000 size: 47656
173
+ Loaded /home/sha0/src/mwemu/maps32/shell32.dll
174
+ 4 sections base addr 0x73800000
175
+ created pe32 map for section `.text` at 0x73801000 size: 3966180
176
+ created pe32 map for section `.data` at 0x73bca000 size: 26872
177
+ created pe32 map for section `.rsrc` at 0x73bd1000 size: 8670296
178
+ /!\ warning: raw sz:12872192 off:12660736 sz:211456 off+sz:12872192
179
+ created pe32 map for section `.reloc` at 0x74416000 size: 211060
180
+ Loaded /home/sha0/src/mwemu/maps32/pstorec.dll
181
+ 5 sections base addr 0x5a800000
182
+ created pe32 map for section `.text` at 0x5a801000 size: 1105
183
+ created pe32 map for section `.data` at 0x5a802000 size: 804
184
+ created pe32 map for section `.idata` at 0x5a803000 size: 480
185
+ created pe32 map for section `.rsrc` at 0x5a804000 size: 9936
186
+ /!\ warning: raw sz:14336 off:13824 sz:512 off+sz:14336
187
+ created pe32 map for section `.reloc` at 0x5a807000 size: 44
188
+ Loaded /home/sha0/src/mwemu/maps32/rasapi32.dll
189
+ 6 sections base addr 0x10000000
190
+ created pe32 map for section `.text` at 0x10001000 size: 812208
191
+ created pe32 map for section `.data` at 0x100c8000 size: 5692
192
+ created pe32 map for section `.idata` at 0x100ca000 size: 9484
193
+ created pe32 map for section `.didat` at 0x100cd000 size: 524
194
+ created pe32 map for section `.rsrc` at 0x100ce000 size: 1296
195
+ /!\ warning: raw sz:875008 off:826880 sz:48128 off+sz:875008
196
+ created pe32 map for section `.reloc` at 0x100cf000 size: 47656
197
+ IAT Bound.
198
+ Loaded /home/sha0/samples/danabot/2023-04-03-MainModule/unpacked2/dbmm_unpacked.dll
199
+ 10 sections base addr 0x1e70000
200
+ created pe32 map for section `.text` at 0x1e71000 size: 31920128
201
+ entry point at 0x22f7968 0x487968
202
+ created pe32 map for section `.itext` at 0x22f6000 size: 36659200
203
+ created pe32 map for section `.data` at 0x22f8000 size: 36667392
204
+ created pe32 map for section `.bss` at 0x236f000 size: 37154816
205
+ created pe32 map for section `.idata` at 0x2489000 size: 38309888
206
+ created pe32 map for section `.didata` at 0x248e000 size: 38330368
207
+ created pe32 map for section `.edata` at 0x248f000 size: 38334464
208
+ created pe32 map for section `.rdata` at 0x2490000 size: 38338560
209
+ created pe32 map for section `.reloc` at 0x2491000 size: 38342656
210
+ /!\ warning: raw sz:372658176 off:334061568 sz:38596608 off+sz:372658176
211
+ created pe32 map for section `.rsrc` at 0x24cd000 size: 38596608
212
+
213
+ ```
214
+
215
+ ### calling xloader keygen function with 1 params.
216
+
217
+ ```python
218
+
219
+ >>> hex(emu.get_reg('eip'))
220
+ '0x22f7968'
221
+
222
+ >>> struct_ptr = 0x03DB000 # somewhere, evrithing is writable.
223
+ >>> xloader_key1_keygen = 0x03DB687
224
+
225
+ >>> eax = emu.call32(xloader_key1_keygen, [struct_ptr])
226
+
227
+ >>> rc4_key = emu.read_string_of_bytes(struct_ptr+1980, 20)
228
+ >>> rc4_key
229
+ '03 00 00 6a 02 51 ff d2 80 3b 00 74 4e 8b 4d 14 6a 08 89 8e '
230
+
231
+ ```
232
+
233
+ other way to do the call:
234
+
235
+ ```python
236
+ >>> struct_ptr = 0x03DB000
237
+ >>> xloader_key1_keygen = 0x03DB687
238
+ >>> old_eip = emu.set_reg('eip', xloader_key1_keygen)
239
+ >>> ret_addr = old_eip
240
+ >>> emu.stack_push32(struct_ptr)
241
+ True
242
+ >>> emu.stack_push32(ret_addr)
243
+ True
244
+ >>> emu.run(ret_addr) # point ret_addr to some mapped place and run until ret_addr
245
+ ```
246
+
247
+
248
+ ### Spawn console by address or by position.
249
+
250
+ ```python
251
+ >>> emu.spawn_console_at_pos(6)
252
+ >>> emu.set_verbose(3)
253
+ >>> emu.run(0)
254
+ shellcode detected.
255
+ 1 0x3c8b97: push ebp ;0x22f000
256
+ 2 0x3c8b97: push ebp ;0x22f000
257
+ 3 0x3c8b98: mov ebp,esp
258
+ 4 0x3c8b9a: mov ecx,[ebp+0Ch]
259
+ 5 0x3c8b9d: mov eax,[ebp+8]
260
+ -------
261
+ 6 0x3c8ba0: xor [eax],ecx
262
+ --- console ---
263
+ =>r eax
264
+ eax: 0x3c0000 3932160 (code)
265
+ =>r ecx
266
+ ecx: 0x464 1124 'AAAABBBB' (struct_buff)
267
+ =>
268
+ ```
269
+
270
+
271
+
@@ -0,0 +1,73 @@
1
+ /target
2
+
3
+ # Byte-compiled / optimized / DLL files
4
+ __pycache__/
5
+ .pytest_cache/
6
+ *.py[cod]
7
+
8
+ # C extensions
9
+ *.so
10
+
11
+ # Distribution / packaging
12
+ .Python
13
+ .venv/
14
+ env/
15
+ .env/
16
+ bin/
17
+ build/
18
+ develop-eggs/
19
+ dist/
20
+ eggs/
21
+ lib/
22
+ lib64/
23
+ parts/
24
+ sdist/
25
+ var/
26
+ include/
27
+ man/
28
+ venv/
29
+ *.egg-info/
30
+ .installed.cfg
31
+ *.egg
32
+
33
+ # Installer logs
34
+ pip-log.txt
35
+ pip-delete-this-directory.txt
36
+ pip-selfcheck.json
37
+
38
+ # Unit test / coverage reports
39
+ htmlcov/
40
+ .tox/
41
+ .coverage
42
+ .cache
43
+ nosetests.xml
44
+ coverage.xml
45
+
46
+ # Translations
47
+ *.mo
48
+
49
+ # Mr Developer
50
+ .mr.developer.cfg
51
+ .project
52
+ .pydevproject
53
+
54
+ # Rope
55
+ .ropeproject
56
+
57
+ # Django stuff:
58
+ *.log
59
+ *.pot
60
+
61
+ .DS_Store
62
+
63
+ # Sphinx documentation
64
+ docs/_build/
65
+
66
+ # PyCharm
67
+ .idea/
68
+
69
+ # VSCode
70
+ .vscode/
71
+
72
+ # Pyenv
73
+ .python-version