Logged as: guest
Login | Register
## No_paste ##


Title: noSentinel v 0.0.1
Author: nessuno
Syntax highlighting: php
  1.  
  2. <?php
  3. class noSentinel
  4. {
  5. #### you MUST modify this email, whit your! ####
  6. protected $ADMIN_noSentinel = "your@address.here";
  7. #### if you want you can modify this file name (that are the databases)####
  8. ### do NOT remove the slashes before file names! ###
  9. protected $XSS_noSentinel = "/xss.txt";
  10. protected $COUNT_noSentinel = "/count.txt";
  11. protected $NUMERIC_noSentinel = "/numeric.txt";
  12. protected $AGENT_noSentinel = "/agent.txt";
  13. protected $BAN_noSentinel = "/ban.txt";
  14. protected $SQL_noSentinel = "/sql.txt";
  15. #### do not touch nothing else ####
  16. protected $to_merge = array();
  17. protected $path = NULL;
  18. public $get = array();
  19. public $post = array();
  20. public $cookie = array();
  21. public $request = array();
  22. public $counter = NULL;
  23. public $version = "0.0.1";
  24.  
  25. #constrctor
  26. public function __construct( $a = NULL, $b = NULL, $c = NULL, $d = NULL )
  27. {
  28. if( (strtolower(trim($a)) == "entities") )
  29. $this->entities();
  30.  
  31. $this->to_merge[1] = $this->to_merge[2] = $this->to_merge[3] = NULL;
  32.  
  33. if( ( $b === $_REQUEST ) || ( $c === $_REQUEST ) || ( $d === $_REQUEST ) )
  34. foreach($_REQUEST as $id => $val)
  35. $this->request[$id] = $val;
  36. else
  37. {
  38. if( $b !== NULL )
  39. {
  40. foreach($b as $id => $val)
  41. $this->get[$id] = $val;
  42. $this->to_merge[1] = 1;
  43. }
  44.  
  45. if( $c !== NULL )
  46. {
  47. foreach($c as $id => $val)
  48. $this->post[$id] = $val;
  49. $this->to_merge[2] = 1;
  50. }
  51.  
  52. if( $d !== NULL )
  53. {
  54. foreach($d as $id => $val)
  55. $this->cookie[$id] = $val;
  56. $this->to_merge[3] = 1;
  57. }
  58.  
  59. $this->request = array_merge( (NULL !== $this->to_merge[1]) ? $this->get : array() , (NULL !== $this->to_merge[2]) ? $this->post : array() , (NULL !== $this->to_merge[3]) ? $this->cookie : array() );
  60. }
  61.  
  62. $this->path = dirname(__FILE__);
  63. $this->counter = intval( file_get_contents( $this->path.$this->COUNT_noSentinel ) );
  64. $this->user_agent( $_SERVER["HTTP_USER_AGENT"] );
  65. $this->ban(CHECK);
  66.  
  67. }
  68.  
  69. #private functions
  70. private function add_counter()
  71. {
  72. $this->counter++;
  73. if($fp = @fopen($this->path.$this->COUNT_noSentinel,'w'))
  74. {
  75. fwrite($fp,$this->counter);
  76. fclose($fp);
  77. }
  78. else echo "<span style=\"color:#FF0000;font-size:7pt;\">Error saving counter file in ". $this->COUNT_noSentinel ."</span>\n";
  79. }
  80.  
  81. private function set_var($name)
  82. {
  83. echo "<span style=\"color:#FF0000;font-size:7pt;\">Request value NOT isset! (function: <strong>". $name ."</strong>)</span><br />\n";
  84. }
  85.  
  86. private function user_agent($var)
  87. {
  88. $var = strtolower($var);
  89. if(preg_match("@<+[^*]+>|acunetix|scanner|libwww-perl@m",$var))
  90. {
  91. $this->add_counter();
  92. if($fp = @fopen($this->path.$this->AGENT_noSentinel,'a'))
  93. {
  94. fwrite($fp,"IP: ". $_SERVER['REMOTE_ADDR'] ." - AGENT: ". $_SERVER["HTTP_USER_AGENT"] ." - DATE & TIME: " .date('d m Y - H:i,s'). "\n");
  95. fclose($fp);
  96. $this->ban(ADD);
  97. }
  98. else echo "<span style=\"color:#FF0000;font-size:8pt;\">Error saving counter file in " . $this->AGENT_noSentinel ."</span>";
  99. die("<center>You must change user agent to view this page<br /><a href=\"http://nessuno.gotdns.org/\">noSentinel</a></center>");
  100. }
  101. }
  102.  
  103. private function ban($opt)
  104. {
  105. $ip = $_SERVER["REMOTE_ADDR"];
  106. if($opt == "ADD")
  107. {
  108. if(filesize($this->path.$this->BAN_noSentinel) == 0)
  109. if($fp = @fopen($this->path.$this->BAN_noSentinel,'w'))
  110. {
  111. fwrite($fp,"127.0.1.1{}0\n");
  112. fclose($fp);
  113. }
  114. else echo "Error opening ban file (". $this->BAN_noSentinel .") to add first IP. Check permission";
  115.  
  116. $arr = file($this->path.$this->BAN_noSentinel);
  117. for($i = 0;$i<count($arr);$i++)
  118. {
  119. $list[$i][0] = substr($arr[$i],0,strpos("{}",$arr[$i])-4);
  120. $list[$i][1] = (int) substr($arr[$i],-2);
  121. }
  122. //cerchiamo l'ip nella prima colonna della matrice
  123. $find_ip = false;
  124. for($i = 0;$i<count($arr);$i++)
  125. if($ip == $list[$i][0])
  126. {
  127. $find_ip = true;
  128. if($list[$i][1]>=3)
  129. {
  130. die('<center>You\'ve been Banned by <a href="http://nessuno.gotdns.org/">noSentinel</a><br />reason: 3 hack attempt detected from your IP<br /><br />If you want to be unbanned send a mail to the <a href="mailto:'. $this->ADMIN_noSentinel .'>admin</a></center>');
  131. }
  132. else $list[$i][1]++;
  133. break;
  134. }
  135. if(!$find_ip)
  136. {
  137. $list[$i][0] = $ip;
  138. $list[$i][1] = 1;
  139. $dest = count($arr)+1;
  140. }
  141. else $dest = count($arr);
  142.  
  143. //creiamo la nuova stringa e salviamola
  144. $str='';
  145. for($i = 0;$i<$dest;$i++)
  146. {
  147. $str.=$list[$i][0]."{}";
  148. $str.=$list[$i][1]."\n";
  149. }
  150. file_put_contents($this->path.$this->BAN_noSentinel,$str);
  151. unset($str,$dest,$list);
  152. }
  153. if($opt == "CHECK")
  154. {
  155. if(filesize($this->path.$this->BAN_noSentinel) == 0)
  156. if($fp = @fopen($this->path.$this->BAN_noSentinel,'w'))
  157. {
  158. fwrite($fp,"127.0.1.1{}0\n");
  159. fclose($fp);
  160. }
  161. else echo "Error opening ban file (".$this->BAN_noSentinel.") to add first IP, check permission";
  162. $arr = file($this->path.$this->BAN_noSentinel);
  163. //creiamo la matrice
  164. for($i = 0;$i<count($arr);$i++)
  165. {
  166. $list[$i][0] = substr($arr[$i],0,strpos("{}",$arr[$i])-4);
  167. $list[$i][1] = (int) substr($arr[$i],-2);
  168. }
  169. //cerchiamo l'ip nella prima colonna della matrice
  170. for($i = 0;$i<count($arr);$i++)
  171. if($ip == $list[$i][0])
  172. {
  173. if($list[$i][1]>=3)
  174. die('<center>You\'ve been Banned by <a href="http://nessuno.gotdns.org/">noSentinel</a><br />reason: 3 hack attempt detected from your IP<br /><br />If you want to be unbanned send a mail to the <a href="mailto:'.$this->ADMIN_noSentinel.'>admin</a></center>');
  175. break;
  176. }
  177. unset($arr,$list);
  178. }
  179. }
  180.  
  181. #public functions
  182. public function show_counter()
  183. {
  184. echo '<span style="font-size:7pt;"><a href="http://nessuno.gotdns.org/">noSentinel</a> Attack locked: '. $this->counter ."</span>";
  185. }
  186.  
  187. public function show_version()
  188. {
  189. echo "<span style=\"font-size:5pt\"><a href=\"http://nessuno.gotdns.org\">noSentinel</a>, version: <strong>".$this->version."</strong></span>";
  190. }
  191.  
  192. public function banner()
  193. {
  194. echo '<br /><div align="center" style="font-size:9pt; margin:2pt;"><strong><a href="http://nessuno.gotdns.org/">noSentinel/</a></strong><br />
  195. <strong><a href="http://nessuno.gotdns.org/forum/">Forum</a><br /></strong></div>';
  196. }
  197.  
  198. public function entities($opt = NULL)
  199. {
  200. if($opt !== NULL)
  201. {
  202. switch($opt)
  203. {
  204. case "GET":
  205. foreach($_GET as $id => $value)
  206. $_GET[$id] = htmlentities($value);
  207. break;
  208.  
  209. case "POST":
  210. foreach($_POST as $id => $value)
  211. $_POST[$id] = htmlentities($value);
  212. break;
  213.  
  214. case "COOKIE":
  215. foreach($_COOKIE as $id => $value)
  216. $_COOKIE[$id] = htmlentities($value);
  217. break;
  218.  
  219. case "REQUEST":
  220. foreach($_REQUEST as $id => $value)
  221. $_REQUEST[$id] = htmlentities($value);
  222. break;
  223. }
  224. }
  225. else
  226. {
  227. foreach($_GET as $id => $value)
  228. $_GET[$id] = htmlentities($value);
  229. foreach($_POST as $id => $value)
  230. $_POST[$id] = htmlentities($value);
  231. foreach($_COOKIE as $id => $value)
  232. $_COOKIE[$id] = htmlentities($value);
  233. foreach($_REQUEST as $id => $request)
  234. $_REQUEST[$id] = htmlentities($value);
  235. }
  236. }
  237.  
  238. #functions for single value, NOT ARRAY but only one elements of them
  239. public function numeric_id_check($var_id, $opt = NULL)
  240. {
  241. if(isset($this->request[$var_id]))
  242. {
  243. if(!is_numeric($this->request[$var_id]) && !empty($this->request[$var_id]))
  244. {
  245. $this->add_counter();
  246. if($fp = @fopen($this->path.$this->NUMERIC_noSentinel,'a'))
  247. {
  248. fwrite($fp,"IP: ". $_SERVER['REMOTE_ADDR'] ." - PAGE: ". $_SERVER['PHP_SELF'] ." - QUERY: ". $this->request[$var_id]. " - DATE & TIME: " .date('d m Y - H:i,s'). "\n");
  249. fclose($fp);
  250. }
  251. else echo "<span style=\"color:#FF0000;font-size:8pt;\">Error saving counter file in " .$this->NUMERIC_noSentinel ."</span>";
  252. if($opt == "BAN")
  253. $this->ban(ADD);
  254. return false;
  255. }
  256. else return true;
  257. }
  258. else
  259. {
  260. $this->set_var( __FUNCTION__ );
  261. return true;
  262. }
  263. }
  264.  
  265. public function xss_id_check($var_id,$opt = NULL)
  266. {
  267. if(isset($this->request[$var_id]))
  268. {
  269. if(is_array($this->request[$var_id]))
  270. foreach($this->request[$var_id] as $id => $value)
  271. $this->xss_check($this->request[$var_id][$id]);
  272. else
  273. {
  274. $acca = urlencode(strtolower(trim($this->request[$var_id])));
  275. if(!empty($this->request[$var_id]) && preg_match("@%26%23[0-9]+|%3C+[^*]+%3E|string\.+fromcharcode|%5C\.[uU]003[cC]+[^*]+%5C\.[uU]003[cC]@m",$acca))
  276. {
  277. $this->add_counter();
  278. if($fp = @fopen($this->path.$this->XSS_noSentinel,'a'))
  279. {
  280. fwrite($fp,"IP: ".$_SERVER['REMOTE_ADDR']." - PAGE: ".$_SERVER['PHP_SELF']." - XSS: ".urldecode($acca)." - DATE & TIME: ".date('d m Y - H:i,s')."\n");
  281. fclose($fp);
  282. unset($acca);
  283. }
  284. else echo "<span style=\"color:#FF0000;font-size:7pt;\">Error saving counter file in ".$this->XSS_noSentinel ."</span>";
  285. if($opt == "BAN")
  286. $this->ban(ADD);
  287. return false;
  288. }
  289. else return true;
  290. }
  291. }
  292. else
  293. {
  294. $this->set_var( __FUNCTION__ );
  295. return true;
  296. }
  297. }
  298.  
  299. public function sql_id_check($var_id,$opt = NULL)
  300. {
  301. if(isset($this->request[$var_id]))
  302. {
  303. if(is_array($this->request[$var_id]))
  304. foreach($this->request[$var_id] as $id => $value)
  305. $this->sql_check($this->request[$var_id][$id]);
  306. else
  307. {
  308. $acca = strtolower(trim($this->request[$var_id]));
  309. if(!empty($this->request[$var_id]) && preg_match("@^'|^\\\"|^-[0-9]+@",$acca))
  310. {
  311. $this->add_counter();
  312. if($fp = @fopen($this->path.$this->SQL_noSentinel,'a'))
  313. {
  314. fwrite($fp,"IP: ".$_SERVER['REMOTE_ADDR']." - PAGE: ".$_SERVER['PHP_SELF']." - XSS: ".urldecode($acca)." - DATE & TIME: ".date('d m Y - H:i,s')."\n");
  315. fclose($fp);
  316. }
  317. else echo "<span style=\"color:#FF0000;font-size:7pt;\">Error saving counter file in ".$this->SQL_noSentinel ."</span>";
  318. if($opt == "BAN")
  319. $this->ban(ADD);
  320. return false;
  321. }
  322. else return true;
  323. }
  324. }
  325. else
  326. {
  327. $this->set_var( __FUNCTION__ );
  328. return true;
  329. }
  330. }
  331.  
  332. public function numeric_check($var, $opt = NULL)
  333. {
  334. $ret = true;
  335. if(in_array($var,$this->request))
  336. foreach($this->request as $id => $value)
  337. if($var == $value)
  338. {
  339. $ret = $this->numeric_id_check($id,$opt);
  340. break;
  341. }
  342. return $ret;
  343. }
  344.  
  345. public function xss_check($var, $opt = NULL)
  346. {
  347. $ret = true;
  348. if(in_array($var,$this->request))
  349. foreach($this->request as $id => $value)
  350. if($var == $value)
  351. {
  352. $ret = $this->xss_id_check($id,$opt);
  353. break;
  354. }
  355. return $ret;
  356. }
  357.  
  358. public function sql_check($var, $opt = NULL)
  359. {
  360. $ret = true;
  361. if(in_array($var,$this->request))
  362. foreach($this->request as $id => $value)
  363. if($var == $value)
  364. {
  365. $ret = $this->sql_id_check($id,$opt);
  366. break;
  367. }
  368. return $ret;
  369. }
  370. }
  371.  
  372. ?>

Text version