-
Notifications
You must be signed in to change notification settings - Fork 2
/
exploit.pl
81 lines (72 loc) · 1.52 KB
/
exploit.pl
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
use strict;
use warnings;
use IO::Socket::INET;
use IO::Select;
my $REMOTE = @ARGV >= 1 && $ARGV[0] eq 'r';
my ($host, $port);
if ($REMOTE) {
$host = '';
$port = 0;
} else {
$host = '127.0.0.1';
$port = 4000;
}
my $s = conn();
my $payload = (
''
);
$s->send($payload);
interact();
sub p { pack 'I<', $_[0] }
sub u { unpack 'I<', $_[0] }
sub h { sprintf '%x', $_[0] }
sub conn {
IO::Socket::INET->new(
PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp',
) or die $@;
}
sub recvuntil {
my ($st, $debug) = @_;
my $ret = '';
while ($ret !~ /\Q$st\E/) {
my $lret = $s->recv(1);
if ($debug && length $lret > 0) {
print $lret;
}
$ret .= $lret;
}
return $ret;
}
sub recvn {
my ($n) = @_;
my $ret = '';
while (length $ret != $n) {
$ret .= $s->recv(1);
}
return $ret;
}
sub interact {
my $sel = IO::Select->new($s, \*STDIN);
while (1) {
for my $fh ($sel->can_read()) {
if ($fh == $s) {
my $text = <$fh>;
unless (defined $text) {
print "*** Connection closed by remote host ***\n";
goto END_INTERACT;
}
print $text;
}
if ($fh == \*STDIN) {
my $line = <$fh>;
unless (defined $line) {
goto END_INTERACT;
}
$s->send($line);
}
}
}
END_INTERACT:
}