From 02e0afd0784de2545461dae6e4db451a17155e96 Mon Sep 17 00:00:00 2001 From: "Matteo Nastasi (mop)" Date: Mon, 15 Sep 2014 18:48:52 +0200 Subject: [PATCH] tor check added --- web/Obj/curl-de-brisk.phh | 94 ++++++++++++++++++++++++++++++++++ webtest/Data/tor_mock_bad.html | 63 +++++++++++++++++++++++ webtest/Data/tor_mock_ok.html | 63 +++++++++++++++++++++++ webtest/cds_test02.php | 94 ++++++++++++++++++++++++++++++++++ webtest/tor_mock.php | 20 ++++++++ 5 files changed, 334 insertions(+) create mode 100755 web/Obj/curl-de-brisk.phh create mode 100644 webtest/Data/tor_mock_bad.html create mode 100644 webtest/Data/tor_mock_ok.html create mode 100755 webtest/cds_test02.php create mode 100644 webtest/tor_mock.php diff --git a/web/Obj/curl-de-brisk.phh b/web/Obj/curl-de-brisk.phh new file mode 100755 index 0000000..9fc5f66 --- /dev/null +++ b/web/Obj/curl-de-brisk.phh @@ -0,0 +1,94 @@ +ctx = $ctx; + $this->user_idx = $user_idx; + $this->user_sess = $user_sess; + $this->conn_ip = $conn_ip; + } +} + +class tor_chk_cmd_cls extends CDS_cmd_cls { + function tor_chk_cmd_cls() + { + parent::__construct("tor_chk", 10); + } + + function create($cds, $ctx, $user_idx, $user_sess, $conn_ip) + { + if ($cds->dbg_get() > 0) { + printf("'tor_chk'::create url:[%s]\n", 'TOR_CHK_URL'); + } + + do { + $opts = array( CURLOPT_HEADER => 0, + CURLOPT_RETURNTRANSFER => 1, + CURLOPT_FORBID_REUSE => true, + CURLOPT_HTTPHEADER => array('Connection: close'), + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => array('QueryIP' => $conn_ip)); + + if (($ch = parent::pre_create($cds, TOR_CHK_URL, $opts)) == FALSE) + break; + + if (parent::create($cds, $ch) == FALSE) + break; + + $cmd = new tor_chk_cmd($this, $ch, $ctx, $user_idx, $user_sess, $conn_ip); + + return $cmd; + } while (FALSE); + + return FALSE; + } + + function process($cmd, $ret) + { + if ($this->dbg_get() > 2) { + printf("CURL: 'tor_chk' process: curl_multi_getcontent\n"); + print_r($ret); + } + + $content = curl_multi_getcontent($cmd->ch_get()); + if ($this->dbg_get() > 0) { printf("'tor_chk' process: [%s]\n", $content); } + + $is_tor = FALSE; + if (mb_strpos($content, + "The IP Address you entered matches one or more active Tor servers", + 0, "UTF-8") !== FALSE) { + printf("WARNING: stripos ok\n"); + $is_tor = TRUE; + } + else if (mb_strpos($content, + "The IP Address you entered is NOT an active Tor server", + 0, "UTF-8") === FALSE) { + printf("WARNING: tor check disabled\n"); + } + else { + printf("WARNING: NOT an active ...\n"); + } + + $cmd->ctx->cds_postprocess($cmd->user_idx, $cmd->user_sess, $cmd->conn_ip, $is_tor); + + return TRUE; + } + + function timeout($cmd) + { + printf("'tor_chk' timeout function reached\n"); + } +} + +?> \ No newline at end of file diff --git a/webtest/Data/tor_mock_bad.html b/webtest/Data/tor_mock_bad.html new file mode 100644 index 0000000..5d641b8 --- /dev/null +++ b/webtest/Data/tor_mock_bad.html @@ -0,0 +1,63 @@ + + + + + + +Tor Network Status -- Tor Exit Query + + +

+ + + + + + + + + + + + + + + + + + +

Tor Network Status -- Tor Exit Query




You can use this page to determine if an +IP address is an active Tor server, and optionally see if that Tor +server's Exit Policy would permit it to exit to a certain destination +IP address and port.


-The IP Address you entered is NOT an active Tor server-


+ + + + + +
+
+ +
+IP Address to Query:
(Required)

+


+Destination IP Address:
(Optional)

+

+Destination Port:
(Optional)

+


+

+
+ +
+ +

+
+ +


+ + + + + +
Tor Network Status v3.6.1
View Complete Change History
Copyright © 2006-2007, Joseph B. Kowalski
Portions Copyright © 2007, Kasimir Gabert
Source code is available under BSD license at project.torstatus.kgprog.com
+ \ No newline at end of file diff --git a/webtest/Data/tor_mock_ok.html b/webtest/Data/tor_mock_ok.html new file mode 100644 index 0000000..1b5e30a --- /dev/null +++ b/webtest/Data/tor_mock_ok.html @@ -0,0 +1,63 @@ + + + + + + +Tor Network Status -- Tor Exit Query + + +

+ + + + + + + + + + + + + + + + + + +

Tor Network Status -- Tor Exit Query




You can use this page to determine if an +IP address is an active Tor server, and optionally see if that Tor +server's Exit Policy would permit it to exit to a certain destination +IP address and port.


-The IP Address you entered matches one or more active Tor servers-

Server name: hviv103


+ + + + + +
+
+ +
+IP Address to Query:
(Required)

+


+Destination IP Address:
(Optional)

+

+Destination Port:
(Optional)

+


+

+
+ +
+ +

+
+ +


+ + + + + +
Tor Network Status v3.6.1
View Complete Change History
Copyright © 2006-2007, Joseph B. Kowalski
Portions Copyright © 2007, Kasimir Gabert
Source code is available under BSD license at project.torstatus.kgprog.com
+ \ No newline at end of file diff --git a/webtest/cds_test02.php b/webtest/cds_test02.php new file mode 100755 index 0000000..bcbacbb --- /dev/null +++ b/webtest/cds_test02.php @@ -0,0 +1,94 @@ +#!/usr/bin/php +cmd_cls_register($tor_chk_cls)) == FALSE) { + fprintf(STDERR, "MAIN: 'tor_chk_cls' registration failed\n"); + exit(1); + } + + if (($debug & 1) == 1) { + printf("MAIN: CDS:\n"); + print_r($cds); + printf("\n"); + } + + // for ($i = -15 ; $i < 30 ; $i++) { + for ($i = 0 ; $i < 10 ; $i++) { + printf("MAIN: START ITERATION %d\n", $i); + + if ($i == 2) { + // Case OK + printf("MAIN: load 'tor_chk'\n"); + if ($cds->execute("tor_chk", $brisk, 24, "caffe", "178.162.193.213") == FALSE) { + printf("MAIN: push 'tor_chk' command failed\n"); + exit(123); + } + } + + else if ($i == 4) { + // Case Malformed output + printf("MAIN: load 'tor_chk'\n"); + if ($cds->execute("tor_chk", $brisk, 24, "caffe", "178.162.193.214") == FALSE) { + printf("MAIN: push 'tor_chk' command failed\n"); + exit(123); + } + } + else if ($i == 6) { + // Case NO + printf("MAIN: load 'tor_chk'\n"); + if ($cds->execute("tor_chk", $brisk, 24, "caffe", "178.162.193.215") == FALSE) { + printf("MAIN: push 'tor_chk' command failed\n"); + exit(123); + } + } + + printf("MAIN:"); + if (($debug & 1) == 1) { + printf(" CDS:\n"); + print_r($cds); + printf("\n"); + } + + printf("MAIN: Call process\n"); + $cds->process(); + sleep(1); + } + printf("MAIN: finished, dump cds:\n"); + print_r($cds); + // start loop + // print status + // if input data execute some command + // if end => clean exit + exit(0); +} + +main(); + +?> \ No newline at end of file diff --git a/webtest/tor_mock.php b/webtest/tor_mock.php new file mode 100644 index 0000000..2b75bd7 --- /dev/null +++ b/webtest/tor_mock.php @@ -0,0 +1,20 @@ +

-The IP Address you entered matches one or more active Tor servers-

Server name: hviv103

+ + readfile("Data/tor_mock_ok.html"); +} +else if ($query_ip == "178.162.193.214") { + echo "NOTHING NOTHING!"; +} +else { + readfile("Data/tor_mock_bad.html"); +} +?> \ No newline at end of file -- 2.17.1