วันจันทร์ที่ 29 กรกฎาคม พ.ศ. 2556

สคิป Bot Boom


ท่องเน็ตอยู่นาน เนื่องจากว่างจัด เลยจัด Google ค้นหาคำว่า Perl Bot Boom เลยไปเจอ Bot ของท่านๆ หนึ่งเขียนไว้ ไม่รู้ว่าของใคร เลยเอามาแปะไว้ที่บล๊อคนี่ละ สำหรับใครที่อยากได้ Bot สำหรับทำวิจัย หรือ อะไรก็ตามแต่ (ไม่รู้ว่า เอาไปใช้ไรกันมั้ง)

    #!/usr/bin/perl
    use strict;
    use warnings;
    use IO::Socket;
    use LWP::UserAgent;
    use Encode;
    #ตั้งค่าบอท
    my $server = "irc.pong-host.com"; #เซิฟเวอร์ IRC นะครับ
    my $login = "Boom_Bot";  #username นะแหละ
    my $owner = "Bongtrop"; #ชื่อเจ้าของเอาไว้สั่งครับ
    my $channel = "#Bongtrop";  #ห้องของห้อง
    my $shell="http://103.22.180.158/bot_boom.php";
    my $nick;
    my $pid=fork();
    my $thr=0;
    #เชื่อมต่อ
    my $sock = new IO::Socket::INET(PeerAddr => $server,
                                    PeerPort => 6667,
                                    Proto => 'tcp') or
                                        die "ไม่สามารถเชื่อมต่อได้\n";
    if ($pid) {
            $nick="BotBoom_Command";
    }
    elsif ($pid==0) {
            $nick="BotBoom_Run";
    }  else {
            print $sock "PRIVMSG ",$channel," :[-] MultiProcress Error\r\n";
    }
    my $ua = LWP::UserAgent->new();
    $ua->agent("Mozilla/5.0 (Windows; U; Windows NT 5.1; en; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4");
    #function Save LOG
    sub saveLOG {
            open LOG,">>log.txt";
            (my $str,my $own)=@_;
            if ($str eq "START") {
                    $str="Procress in ".localtime." by ".$own."\n";
            }
            elsif ($str eq "END") {
                    $str="------------------------END PROCRESS------------------------\n\n";
            }
            $str = encode("utf-8", decode("tis-620", $str));
            print LOG $str;
            close LOG;
    }
    my $firstID;
    #function SMF
    sub smf {
            saveLOG("START","Bot");
            my $url="http://picpost.mthai.com/category/sexy-girl";
            print $sock "PRIVMSG ",$channel," : 7[+] เริ่มทำการดึงจากเว็บ $url\r\n";
            saveLOG("[+] เริ่มทำการดึงจากเว็บ $url\n");
            my $respone=$ua->get($url);
           
            my @line=split(/\n/,$respone->content);
            my $c=0;
            foreach (@line) {
                    if ((my $id)=$_=~/<h4><a href=\"\/view\/(.*)\" title=/) {
                            my $lastid;
                            open INFILE,"id.txt";
                            while (<INFILE>) {
                                    chomp;
                                    $lastid=$_;
                            }
                            close INFILE;
                            if ($lastid eq $id) {
                                    print $sock "PRIVMSG ",$channel," : 4[-] ไม่พบหัวข้อ Picpost ใหม่ฮะ\r\n";
                                    saveLOG ("[-] ไม่พบหัวข้อ Picpost ใหม่ฮะ\n","Bot");
                                    last;
                            }
                            if ($c==0) {
                                    open OUTFILE,">id.txt";
                                    print OUTFILE $id;
                                    close OUTFILE;
                            }
                            $url="http://picpost.mthai.com/view/".$id;
                            $respone=$ua->get($url);
                            my ($subject)=$respone->content=~/<title>(.*) \| picpost/;
                            my @line2=split(/\n/,$respone->content);
                            my $outsj = encode("tis-620", decode("utf-8", $subject));
                            print $sock "PRIVMSG ",$channel," : 7[-] พบหัวข้อ Picpost $outsj ไอดี $id\r\n";
                            saveLOG ("[-] พบหัวข้อ Picpost $outsj ไอดี $id\n","Bot");
                            my $body="<center>";
                            foreach (@line2) {
                                    if ((my $pic)=$_=~/<a href=\"\/pic\/$id\/(.*)\" class=\"fullsize\"/) {
                                            $body.='<img src="http://picpost.mthai.com/pic/'.$id.'/'.$pic.'"><br>';
                                    }
                            }
                            $body.='</center>';
                            if ($subject=~/Page not found/ or $subject eq "" or $body eq "" or $body=~/Page not found/) {
                                    print $sock "PRIVMSG ",$channel," : 4[-] เว็บ Mthai มีปัญหาเลยลามมาหากระปมเลย ><\r\n";
                                    saveLOG ("[-] เว็บ เดลินิวมีปัญหาเลยลามมาหากระปม ><\n","Bot");
                                    last;
                            }
                            $respone = $ua->post($shell,["subject"=>$subject,"body"=>$body,"idBoard"=>3]);
                            print $sock "PRIVMSG ",$channel," : 7[+] อัพโหลดสู่ SMF ".$respone->content."\r\n";
                            saveLOG ("[+] อัพโหลดสู่ SMF ".$respone->content."\n","Bot");
                            $c++;
                    }
            }
            print $sock "PRIVMSG ",$channel," : 7[+] รอสักครู่จะรันอีกทีนะฮะ ทำเรื่อยๆเดียวโดนบ๊อก\r\n";
            saveLOG ("[+] รอสักครู่จะรันอีกทีนะฮะ ทำเรื่อยๆเดียวโดนบ๊อก\n","Bot");
            saveLOG ("END","Bot");
    }
    print $sock "NICK $nick\r\n";
    print $sock "USER $login 8 * :I'm botSMF\r\n";
    while (my $input = <$sock>) {
        if ($input =~ /004/) {
            last;
        }
        elsif ($input =~ /433/) {
            die " 4[-] ชื่อถูกใช้ไปแล้ว";
        }
    }
    #เข้าสู่ห้อง
    print $sock "JOIN $channel\r\n";
    my $count=0;
    if ($pid) {
            while (my $input = <$sock>) {
                    chop $input;
                    chop $input;
                    #ส่งค่ากลับเมื่อมีการ ping มา จาก server
                    if ($input=~/PING/) {
                            (my $pong)=$input=~m/PING (.*)/;
                            print $sock 'PONG '.$pong." : \r\n";
                            if ($thr==1 and $count>10) {
                                    $count=0;
                                    print $sock "PRIVMSG ",$channel," : 12[+] กำลังเริ่มสั่งให้มันรัน อาจจะสั่งงานไม่ได้ซัก 2-5 วินาที รอแปปนะ\r\n";
                                    sleep 3;
                                    print $sock "PRIVMSG ",$channel," :9qcp34iwfipoj230cjaesff323r0ijasdfj2r0irskfjasv\r\n";
                            }
                            $count++;
                    }
                    if ($input=~/^\:$owner\!/ or $input=~/^\:thejestei2\!/) {
                            (my $own)=$input=~/^\:(.*)\!/;
                            saveLOG("START",$own);
                            saveLOG($input."\n",$own);
                            saveLOG("END",$own);
                            if ($input=~/ปิดระบบ/) {
                                    print $sock "PRIVMSG ",$channel," : 4[-] เริ่มทำการปิดระบบ\r\n";
                                    kill 'KILL' => $pid;
                                    last;
                            }
                            if ($input=~/ทดสอบ/) {
                                    print $sock "PRIVMSG ",$channel," : 3เรียบร้อยทุกอย่างฮะ >< \r\n";
                            }
                            if ($input=~/ถอย/) {
                                    $thr=0;
                                    print $sock "PRIVMSG ",$channel," : 4[-] สั่งให้บอทหยุดดึงเรียบร้อยแล้วฮะ \r\n";
                            }
                            if ($input=~/กี่cแล้ววะแม้ง/) {
                                    print $sock "PRIVMSG ",$channel," : 4[!] อย่าพึ่งโกรธสิฮะ ตอนนี้ $count c แล้วฮะจักกะแปปป\r\n";
                            }
                            if ($input=~/คำสั่ง/) {
                                    print $sock "PRIVMSG ",$channel," : 12[+] มีคำสั่ง 6 คำสั่ง\r\n";
                                    print $sock "PRIVMSG ",$channel," : \r\n";
                                    print $sock "PRIVMSG ",$channel," : 3 1) ลุย ใช้เริ่มทำงาน\r\n";
                                    print $sock "PRIVMSG ",$channel," : 3 2) สถานะ ตรวจสอบสถานะ Bot\r\n";
                                    print $sock "PRIVMSG ",$channel," : 3 4) ไอดี ใช้ตรวจสอบไอดีล่าสุดของข่าว\r\n";
                                    print $sock "PRIVMSG ",$channel," : 3 5) แก้ไอดี ใช้สำหรับแก้ไขไอดีล่าสุดของข่าว\r\n";
                                    print $sock "PRIVMSG ",$channel," : 3 5) ถอย ใช้หยุดการทำงาน Bot ไม่ให้ดึงข่าว\r\n";
                                    print $sock "PRIVMSG ",$channel," : 3 6) ล๊อก ใช้สำหรับเช๊คล๊อกว่ามะอะไรเปลี่ยนแปลงไปบ่าง\r\n";
                                    print $sock "PRIVMSG ",$channel," : 3 7) ลบล๊อก ใช้สำหรับเคลียล๊อกที่ผ่านมา\r\n";
                                    print $sock "PRIVMSG ",$channel," : 3 8) ปิดระบบ ใช้ออกจาก IRC\r\n";
                            }
                            if ($input=~/ลุย/) {
                                    print $sock "PRIVMSG ",$channel," :9qcp34iwfipoj230cjaesff323r0ijasdfj2r0irskfjasv\r\n";
                                    print $sock "PRIVMSG ",$channel," : 12[+] สั่งงาน BotSMF_Run เรียบร้อยแล้ว\r\n";
                                    $thr=1;
                            }
                            if ($input=~/ลบล๊อก/) {
                                    unlink("log.txt");
                                    print $sock "PRIVMSG ",$channel," : 12[+] ลบล๊อกสำเร็จแล้วฮะ ><\r\n";
                            }
                            elsif ($input=~/ล๊อก/) {
                                    print $sock "PRIVMSG ",$channel," : 12[+] ไฟย์ล๊อก ก็ ไฟย์ log.txt ดูด้านข้าง";
                            }
                            if ($input=~/สถานะ/) {
                                    if ($thr==0) {
                                            print $sock "PRIVMSG ",$channel," : 4[-] Bot ยังไม่ได้เริ่มทำงาน\r\n";
                                    } else {
                                            print $sock "PRIVMSG ",$channel," : 12[+] Bot กำลังทำงานอยู่\r\n";
                                    }
                            }
                            if ((my $idedit)=$input=~/แก้ไอดีเป็น (.*)/) {
                                    open OUTFILE,">id.txt";
                                    print OUTFILE $idedit;
                                    close OUTFILE;
                                    print $sock "PRIVMSG ",$channel," : 12[+] ทำการแก้ไอดีเป็น $idedit เสร็จแล้ว\r\n";
                            }
                            elsif ($input=~/ไอดี/) {
                                    open INFILE,"id.txt";
                                    my $sid;
                                    while (<INFILE>) {
                                            $sid=$_;
                                    }
                                    close INFILE;
                                    print $sock "PRIVMSG ",$channel," : 12[+] ไอดีล่าสุดคือ $sid\r\n";
                            }
                    }
            }
    }
    elsif ($pid==0) {
            while (my $input = <$sock>) {
                    chop $input;
                    chop $input;
                    if ($input=~/PING/) {
                            (my $pong)=$input=~m/PING (.*)/;
                            print $sock 'PONG '.$pong." : \r\n";
                    }
                    if ($input=~/^\:BotBoom_Command\!/) {
                            if ($input=~/9qcp34iwfipoj230cjaesff323r0ijasdfj2r0irskfjasv/) {
                                    smf();
                            }
                    }
            }
    } else {
            print $sock "PRIVMSG ",$channel," : 4[-] MultiProcress Error\r\n";
    }

ของใครก็ไม่รู้ ลิงค์นี้ละ http://pastebin.com/2PEetqQq