我在过去的日子里一直在修补网络服务器漏洞利用,而且我在Python中遇到了一些问题。我在python中写了一个格式错误的http POST数据,当我将它粘贴到Http Live Headers并重放请求时,它会在100次中完成100次。
问题是当我尝试删除Replay标题部分并只使用python来完成整个事情时,python似乎没有发送完整的POST命令。
我用这个:
<?php require('includes/config.php');
include("includes/conf_proc.php");
//if not logged in redirect to login page
if(!$user->is_logged_in()){ header('Location: login.php'); }
//define page title
$title = 'Account Page';
//include header template
require('layout/header.php');
$img_query = "SELECT * FROM `images` WHERE memberID='".$_SESSION['memberID']."'";
$img = mysqli_query($conn, $img_query);
$rows = mysqli_fetch_assoc($img);
$num_row = mysqli_num_rows($img);
?>
<div class="container">
<h2 style="margin-bottom:10px;margin-left:15px;">User account</h2>
<div class="row" style="background-color: white;">
<div class="col-sm-6 col-md-12" style="margin-top:20px; margin-left:90px">
<?php
echo '<img src="./demo/covers/'.$rows['image'].'" />';
echo $num_row;
?>
</div>
</div>
</div>
<?php
//include header template
require('layout/footer.php');
?>
PostCommand是~36000个字符。当我在Python方法之后查看堆栈时,它至少能够导致异常,但是不能发送足够的数据来覆盖SEH。每次有不同数量的信息进入Web服务器时。
是否有可能缺少强制Python发送整个命令的参数,或者仅仅是HTTP Headers只是在背景中做了一些我没有意识到的事情?
我在发送之前将PostCommand写入磁盘,下面是它的样子:
send = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
send.connect(('hostname', 80))
send.send(PostCommand)
send.close()
答案 0 :(得分:0)
socket.send()
方法将尽可能多地写入,最多可达到您提供的缓冲区大小。但由于许多原因,写入的字节数可能小于缓冲区大小。
应用程序始终负责检查是否已写入完整缓冲区,并在需要时自行重新发送。这来自底层的C套接字库。请参阅man send(2)
或socket.send()
方法的文档。
这样做的方法通常是:
nsent = 0
while nsent < len(buffer):
nsent += sock.send(buffer[nsent])
答案 1 :(得分:0)
我最终使用了httplib,而且每次都看起来效果很好。
conn = httplib.HTTPConnection("hostname",80)
conn.request("POST", "/Path", PostCommand)