forked from mandiant/pycommands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpivy_config.py
170 lines (146 loc) · 5.39 KB
/
pivy_config.py
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
163
164
165
166
167
168
169
170
# Copyright (c) 2013 FireEye, Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
import re
import binascii
import struct
import string
from immlib import *
from immutils import *
str_regex = r"^([\w\x20\x00\t\\\:\-\.\&\%\$\#\@\!\(\)\*]+)$"
def main(args):
imm = Debugger()
regs = imm.getRegs()
structaddr = regs["ESI"]
if len(args) > 0:
structaddr = int(args[0], 16)
imm.log("PI struct address: 0x%08X" % structaddr)
id = imm.readString(structaddr + int("AFA", 16))
group = imm.readString(structaddr + int("BF9", 16))
pw = imm.readMemory(structaddr + int("145", 16), 32)
imm.log("ID: %s" % id)
imm.log("Group: %s" % group)
match = re.match(str_regex,pw)
if match is not None:
pw = string.strip(pw, "\x00")
imm.log("Password: %s" % pw)
else:
imm.log("Password: 0x%s" % (binascii.hexlify(pw)))
mutex = imm.readString(structaddr + int("3FB", 16))
imm.log("Mutex: %s" % mutex)
proxy = False
if imm.readShort(structaddr + int("2C1", 16)) == 1:
proxy = True
if proxy:
cnt = 0
C2offset = int("2C5", 16)
while True:
str_len = imm.readMemory(structaddr + C2offset + cnt, 1)
cnt = cnt + 1
str_len = struct.unpack('B', str_len)[0]
domaindata = imm.readMemory(structaddr + C2offset + cnt, str_len)
domain = ""
for c in domaindata:
if c != "\x00":
domain += c
else:
break
cnt = cnt + str_len
imm.log("C2: %s" % domain)
version = imm.readMemory(structaddr + C2offset + cnt, 1)
cnt = cnt + 1
version = struct.unpack('B', version)[0]
imm.log("C2 version: %d" % version)
port = imm.readShort(structaddr + C2offset + cnt)
cnt = cnt + 2
imm.log("C2 port: %d" % port)
if struct.unpack('B', imm.readMemory(structaddr + C2offset + cnt, 1))[0] == 0:
break
imm.log("***********")
cnt = 0
C2offset = int("190", 16)
while True:
str_len = imm.readMemory(structaddr + C2offset + cnt, 1)
cnt = cnt + 1
str_len = struct.unpack('B', str_len)[0]
domaindata = imm.readMemory(structaddr + C2offset + cnt, str_len)
domain = ""
for c in domaindata:
if c != "\x00":
domain += c
else:
break
cnt = cnt + str_len
if proxy is True:
imm.log("Proxy: %s" % domain)
else:
imm.log("C2: %s" % domain)
version = imm.readMemory(structaddr + C2offset + cnt, 1)
cnt = cnt + 1
version = struct.unpack('B', version)[0]
if proxy is True:
imm.log("Proxy version: %d" % version)
else:
imm.log("C2 version: %d" % version)
port = imm.readShort(structaddr + C2offset + cnt)
cnt = cnt + 2
if proxy is True:
imm.log("Proxy port: %d" % port)
else:
imm.log("C2 port: %d" % port)
if struct.unpack('B', imm.readMemory(structaddr + C2offset + cnt, 1))[0] == 0:
break
imm.log("***********")
implant = imm.readString(structaddr + int("12D", 16))
ads = imm.readMemory(structaddr + int("D12", 16), 1)
ads = struct.unpack('B', ads)[0]
copydir = struct.unpack('B', imm.readMemory(structaddr + int("3F7", 16), 1))[0]
destination = ""
if copydir == 1:
destination = "%WINDIR%"
elif copydir == 2:
destination = "%WINDIR%\\system32"
if ads == 1:
destination += ':'
elif destination != "":
destination += '\\'
if destination != "":
implant = destination + implant
imm.log("Implant filename: %s" % implant)
activesetup = struct.unpack('B', imm.readMemory(structaddr + int("3F6", 16), 1))[0]
if activesetup == 1:
runkey = imm.readString(structaddr + int("4B3", 16))
runname = imm.readString(structaddr + int("40F", 16))
imm.log("Active Setup key: %s" % runkey)
imm.log("Active Setup value name: %s" % runname)
run = struct.unpack('B', imm.readMemory(structaddr + int("D09", 16), 1))[0]
if run == 1:
runname = imm.readString(structaddr + int("E12", 16))
imm.log("HKLM run value name: %s" % runname)
keylogconf = imm.readMemory(structaddr + int("3FA", 16), 1)
keylogconf = struct.unpack('B', keylogconf)[0]
if keylogconf == 1:
imm.log("Keylogger installed")
if keylogconf == 1:
keylog = imm.readString(structaddr + int("7B0", 16))
imm.log("Key stroke log file: %s" % keylog)
return "Complete.."