Advertisement
MindenCucc

UnbanMii 2.0 backend API.php

Jul 27th, 2017
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.59 KB | None | 0 0
  1. <?
  2.  
  3. header('Content-Type: text/plain');
  4.  
  5. if(!isset($_GET['e'])) die('Missing event');
  6.  
  7. $evt = $_GET['e'];
  8.  
  9. if($evt != 'up' && $evt != 'down' && $evt != 'restore') die('Invalid event \'' . $evt . '\'');
  10.  
  11. $pdata = file_get_contents('php://input', false, NULL, 0, 0x390);
  12. if($pdata === FALSE) die('Failed to read stdin');
  13.  
  14. if(strlen($pdata) != 0x380) die('Invalid POST length');
  15.  
  16. $pdata = strtoupper(bin2hex($pdata));
  17.  
  18. if($evt == 'up')
  19. {
  20.     $chk = substr($pdata, 0x200, 0x10);
  21.     if($chk != '0000000000000000')
  22.     {
  23.         if
  24.         (
  25.             substr($chk, 0, 2) == '00' && substr($chk, 2, 2) != '00' &&
  26.             substr($chk, 4, 0xC) == '000000000000'
  27.         )
  28.             die('Dev FriendCodeSeed not supported');
  29.         else
  30.             die('Invalid FriendCodeSeed');
  31.     }
  32.    
  33.     $chk = substr($pdata, 0x210, 0x10);
  34.     if($chk == '0000000000000000') die('Zero Friendcode');
  35.    
  36.     $chk = substr($pdata, 0, 0x220);
  37.     $chk2 = substr($pdata, 0x118 * 2, 0x220);
  38.     //if($chk != $chk2) die('Upload of non-factory FriendCodeSeed is not allowed');
  39. }
  40.  
  41. $chk = substr($pdata, 0x110 * 2, 8);
  42. if($chk != '53454544') die('Invalid authdata');
  43.  
  44. $NANDCID = substr($pdata, 0x370 * 2, 0x10 * 2);
  45.  
  46. $keusr = ''; //note: edited this out, the rest of the script is unchanged
  47. $kepasswd = ''; //note: edited this out, the rest of the script is unchanged
  48. if(!isset($_SERVER['HTTP_USER_AGENT']) || $_SERVER['HTTP_USER_AGENT'] != 'UnbanMii/lulz')
  49. {
  50.     $keusr = 'BanMii';
  51.     $kepasswd = '';
  52. }
  53. $link = new mysqli('localhost', $keusr, $kepasswd, 'BanMii');
  54. if(mysqli_connect_error()) die('DB connect error (' . mysqli_connect_errno() . '): ' . mysqli_connect_error());
  55. $stmt = $link->stmt_init();
  56.  
  57. $pdata = substr($pdata, 0, 0x361 * 2);
  58.  
  59. if(!$stmt->prepare("SELECT RawPOST, flags FROM users WHERE NANDCID = ?")) die('Failed to prepare (' . $stmt->errno . '): ' . $stmt->error);
  60. if(!$stmt->bind_param('s', $NANDCID)) die('Failed to bind param (' . $stmt->errno . '): ' . $stmt->error);
  61. if(!$stmt->execute()) die('Failed to query (' . $stmt->errno . '): ' . $stmt->error);
  62. if(!$stmt->store_result()) die('Failed to kqueryresult (' . $stmt->errno . '): ' . $stmt->error);
  63. if(!$stmt->bind_result($rpost, $rflag)) die('Failed to Toast Toast (' . $stmt->errno . '): ' . $stmt->error);
  64. if(!$stmt->fetch())
  65. {
  66.     if($evt == 'restore') die('Can\'t restore non-existant Data');
  67.     if(!$stmt->prepare("INSERT INTO users SET NANDCID = ?, datetime = ?, RawPOST = ?, flags = ?")) die('Failed to prepare (' . $stmt->errno . '): ' . $stmt->error);
  68.     $dt = time();
  69.     $flag = 0;
  70.     if(!$stmt->bind_param('sisi', $NANDCID, $dt, $pdata, $flag)) die('Failed to bind param (' . $stmt->errno . '): ' . $stmt->error);
  71.     if(!$stmt->execute()) die('Failed to insert Dick in Toaster (' . $stmt->errno . '): ' . $stmt->error);
  72.     $rpost = substr($pdata, 0, 0x361 * 2);
  73.     $rflag = 0;
  74. }
  75.  
  76. if($stmt->num_rows > 1) die('wut count ' . $stmt->num_rows);
  77. else if($stmt->num_rows == 1 || $stmt->affected_rows > 0)
  78. {
  79.     if($evt != 'restore')
  80.     {
  81.         if($rflag & 2) die('You\'re banned from using this Service');
  82.         if(substr($rpost, 0x250 * 2, 0x111 * 2) != substr($pdata, 0x250 * 2, 0x111 * 2)) die('Region-Change not allowed');
  83.     }
  84.     if($evt == 'up')
  85.     {
  86.         $rtseed = substr($pdata, 0, 0x110 * 2);
  87.         if(!$stmt->prepare("SELECT NANDCID, flags FROM users WHERE RawPOST LIKE CONCAT(?,'%') LIMIT 1")) die('Failed to prepare (' . $stmt->errno . '): ' . $stmt->error);
  88.         if(!$stmt->bind_param('s', $rtseed)) die('Failed to bind param for Seedtest (' . $stmt->errno . '): ' . $stmt->error);
  89.         if(!$stmt->execute()) die('Failed to query seedtest (' . $stmt->errno . '): ' . $stmt->error);
  90.         if(!$stmt->bind_result($rNANDCID, $rflag)) die('Failed to bind param for Seedtest (' . $stmt->errno . '): ' . $stmt->error);
  91.         if(!$stmt->fetch()) die('Programming Error, Seed not found!');
  92.         if($stmt->fetch()) die('Programming Error, Seed not found!');
  93.         if($NANDCID != $rNANDCID && $rNANDCID != '00000000000000000000000000000000') die('This seed is not owned by you');
  94.         if($rflag & 1) die('Your Seed is already queued');
  95.         if($rflag & 6) die('This Seed is banned from this service');
  96.         $rflag |= 1;
  97.         if(!$stmt->prepare("UPDATE users SET flags = ? WHERE NANDCID LIKE ? AND RawPOST LIKE CONCAT(?,'%')")) die('Failed to prepare (' . $stmt->errno . '): ' . $stmt->error);
  98.         if(!$stmt->bind_param('iss', $rflag, $NANDCID, $rtseed)) die('Failed to bind param for update (' . $stmt->errno . '): ' . $stmt->error);
  99.         if(!$stmt->execute()) die('Failed to update database (' . $stmt->errno . '): ' . $stmt->error);
  100.         if($stmt->affected_rows != 1) die('Please report this: ' . $stmt->affected_rows . '-' . $NANDCID);
  101.     }
  102. }
  103. else die('Invalid state: ' . $stmt->num_rows . '-' . $stmt->affected_rows);
  104.  
  105. if($evt == 'up') die('Thank you for your contribution!');
  106. if($evt != 'down') die('Programming Error, this should never happen!');
  107.  
  108. if(!$stmt->prepare("SELECT RawPOST FROM users WHERE flags & 1 = 1 ORDER BY datetime ASC LIMIT 1")) die('Failed to prepare Seed (' . $stmt->errno . '): ' . $stmt->error);
  109. if(!$stmt->execute()) die('Failed to query Seed (' . $stmt->errno . '): ' . $stmt->error);
  110. if(!$stmt->bind_result($rseed)) die('Failed to bind Result (' . $stmt->errno . '): ' . $stmt->error);
  111. if(!$stmt->fetch()) die('we\'re out of seeds >_>');
  112. $ssed = substr($rseed, 0, 0x110 * 2);
  113. if(substr($pdata, 0, 0x110 * 2) == $ssed) die('You\'re already using the latest Seed');
  114. die(hex2bin($ssed));
  115.  
  116. $stmt->close();
  117. $link->close();
  118.  
  119. die('well then');
  120. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement