-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpastebin.pl
More file actions
109 lines (95 loc) · 2.8 KB
/
pastebin.pl
File metadata and controls
109 lines (95 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/perl -w
#
#Simple perl script to parse pastebin to alert on keywords of interest.
#1)Install the the LWP and MIME perl modules
#2)Create two text files one called keywords.txt and tracker.txt
#2a)keywords.txt is where you need to enter keywords you wish to be alerted on, one per line.
#3)Edit the code below and enter your smtp server, from email address and to email address.
#4)Cron it up and receive alerts in near real time
#
use Data::Dumper;
use LWP::Simple;
use LWP::UserAgent;
use MIME::Lite;
MIME::Lite->send('smtp','#enter smtp server', Timeout=>60);
my $ua = new LWP::UserAgent;
$ua->agent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1");
my $req = new HTTP::Request GET => 'http://pastebin.com/archive';
my $res = $ua->request($req);
my $pastebin = $res->content;
#date
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my $datestring = sprintf("%4d-%02d-%02d",($year + 1900),($mon+1),$mday-1);
my $dir = sprintf("%4d-%02d",($year + 1900),($mon+1));
open (MYFILE, 'keywords.txt');
my @keywords = <MYFILE>;
chomp(@keywords) ;
my $regex = join('|', @keywords);
my $tracking_file = 'tracker.txt';
my @links = getlinks();
if (@links) {
foreach $line (@links){
if (checkurl($line) == 0){
my $request = "http://pastebin.com/$line\n";
my $link = $line;
my $req = new HTTP::Request GET => "$request";
my $res = $ua->request($req);
my $content = $res->content;
my @data = $content;
foreach $line (@data){
if ($content =~ m/\<textarea.*?\)\"\>(.*?)\<\/textarea\>/sgm){
@data = $1;
print $content;
foreach $line (@data){
if ($line =~ m/($regex)$/i){
storeurl($link);
print "$request $line\n";
my $msg = MIME::Lite->new(
From => '#enter from address',
To => '#enter your email address;',
Cc => '',
Subject => "Keyword Detected ($1) $request",
Type => 'multipart/mixed',
Data =>"",
);
$msg->attach(
Type => 'TEXT',
Data => "\n\n$line\n\n",
);
$msg->send;
}
}
}
}
}
}
}
sub getlinks{
my @results;
if (defined $pastebin) {
@data = $pastebin;
foreach $line (@data){
while ($line =~ m/border\=\"0\"\s\/\>\<a\shref\=\"\/(.*?)"\>/g){
my $url = $1;
push (@results, $url);
}
}
}
return @results;
}
sub storeurl {
my $url = shift;
open (FILE,">> $tracking_file") or die("cannot open $tracking_file");
print FILE $url."\n";
close FILE;
}
sub checkurl {
my $url = shift;
open (FILE,"< $tracking_file") or die("cannot open $tracking_file");
foreach my $line ( <FILE> ) {
if ( $line =~ m/$url/i ) {
return 1;
}
}
return 0;
}