-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutils.cna
More file actions
140 lines (111 loc) · 2.45 KB
/
Copy pathutils.cna
File metadata and controls
140 lines (111 loc) · 2.45 KB
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
# include like:
# include(script_resource("utils.cna"));
# return random string of length $1. uses characters a-zA-Z0-9
sub randstr {
local('$length $ret $charset');
$length = $1;
$charset = 'abcdefghijklmnopqrstuvwxyz' . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
for ($i = 0; $i < $length; $i++) {
$index = rand() * 1000 % strlen($charset);
$ret .= charAt($charset, $index);
}
return $ret;
}
# return random number between $1 and $2 or up to $1
sub rrand {
if ($2) {
$min = $1;
$max = $2;
} else {
$min = 0;
$max = $1;
}
return (rand() * 10000) % ($max - $min + 1) + $min;
}
# return random number of spaces between 1 and $1
sub randspace {
$max = $1;
$ret = '';
$num = rrand(1, $max);
for ($i = 0; $i < $num; $i++) {
$ret .= ' ';
}
return $ret;
}
# return random number of newlines between 1 and $1
sub randlines {
$max = $1;
$ret = '';
$num = rrand(1, $max);
for ($i = 0; $i < $num; $i++) {
$ret .= "\n";
}
return $ret;
}
# check if beacon is admin (including SYSTEM)
sub isAdmin {
local('$bid $user');
$bid = $1;
if (-isadmin($bid)) {
return true;
}
$user = beacon_info($bid, 'user');
if (lc($user) eq 'system') {
return true;
}
return false;
}
sub pspath {
return 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe';
#$bid = $1;
#if ($bid && -is64 $bid) {
# return 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe';
#} else {
# return 'C:\Windows\powershell.exe';
#}
}
# findprocess(bid, proc, callback)
sub findprocess {
$bid = $1;
$proc = $2;
$callback = $3;
bps($bid, lambda({
local('$pid $name $entry $bid $content');
$bid = $1;
$content = $2;
@procs = @();
foreach $entry (split("\n", $content)) {
($name, $null, $pid, $arch) = split("\\s+", $entry);
if ($name eq $proc) {
push(@procs, %(pid => $pid, arch => $arch));
}
}
[$callback: $bid, @procs]
}, $callback => $callback, $proc => $proc));
}
# defaultListener()
sub defaultListener {
foreach $listener (listeners_local()) {
if (($listener ismatch 'http.*') || ($listener ismatch 'main_.*')) {
return $listener;
}
}
return $null;
}
# explorerstome(bid, file)
sub explorerstomp {
$bid = $1;
$file = $2;
btimestomp($bid, $file, 'c:/windows/explorer.exe');
}
# uploadto(bid, local_file, remote_file)
sub uploadto {
$bid = $1;
$local_file = $2;
$remote_file = $3;
# read in file
$handle = openf($local_file);
$data = readb($handle, -1);
closef($handle);
bupload_raw($bid, $remote_file, $data, $local_file);
}