-
Notifications
You must be signed in to change notification settings - Fork 0
/
Knocker.pl
189 lines (154 loc) · 3.92 KB
/
Knocker.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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket;
use Term::ANSIScreen qw/:color /;
use Term::ANSIScreen qw(cls);
use Win32::Console;
use Win32::Console::ANSI;
my $CONSOLE=Win32::Console->new;
$CONSOLE->Title('BwE Port Knocker');
START:
cls();
my $BwE = (colored ['bold magenta'], qq{
===========================================================
| __________ __________ |
| \\______ \\ __ _ _\\_ ____/ |
| | | _// \\/ \\/ /| __)_ |
| | | \\\\ // \\ |
| |______ / \\__/\\__//______ / |
| \\/ Port Knocker \\/ |
| |
===========================================================\n\n});
print $BwE;
my $target;
my $port_list;
my $delay;
my $ssh_port;
# Grab inputs
print "Enter Target: ";
chop ($target = <stdin>);
# Keyword Auto-filler! Make life easy.
if ($target eq "keyword1")
{
$target = "10.0.0.1";
$port_list = "1111 2222 3333 4444";
$delay = "0.5";
$ssh_port = "666";
goto SKIP;
}
if ($target eq "keyword2")
{
$target = "10.0.0.1";
$port_list = "1111 2222 3333 4444";
$delay = "0.5";
$ssh_port = "666";
goto SKIP;
}
if ($target eq "keyword3")
{
$target = "10.0.0.1";
$port_list = "1111 2222 3333 4444";
$delay = "0.5";
$ssh_port = "0";
goto SKIP;
}
if ($target eq "keyword4")
{
$target = "10.0.0.1";
$port_list = "1111 2222 3333 4444";
$delay = "0.5";
$ssh_port = "0";
goto SKIP;
}
print "Enter Ports: ";
chop ($port_list = <stdin>);
print "Enter Delay (Sec): ";
chop ($delay = <stdin>);
print "Enter SSH Port: ";
chop ($ssh_port = <stdin>);
# If no target or port entered
if ($target eq "" | $port_list eq "")
{
print "\nEmpty Target/Port!\n";
goto QUIT;
}
# If no delay entered, put in the default
if ($delay eq "")
{
$delay = "0.5";
}
# If no SSH port entered, put in the default
if ($ssh_port eq "")
{
$ssh_port = "22";
}
# Skip to preset
SKIP:
# Proof of functionality - Or just incase its already open!
if ($ssh_port eq "0")
{
# NO SSH PORT REQUIRED
} else {
print "\n===========================================================\n";
print "\nChecking SSH port $ssh_port...\n";
if( my $socket = IO::Socket::INET->new(PeerAddr => $target , PeerPort => $ssh_port , Proto => 'tcp' , Timeout => 1 ))
{
print colored ['bold green'], "Port $ssh_port is already open\n" ;
goto QUIT;
}
else
{
print colored ['bold red'], "Port $ssh_port is closed\n" ;
}
}
print "\n===========================================================\n\n";
# Split input per spaced port number
my @ports_list = split / /, $port_list;
# Loop the list of ports
foreach my $port ( @ports_list ) {
print "Knocking port $port\n";
# Attempt connection to the port via TCP
my $socket = IO::Socket::INET->new(PeerAddr => $target , PeerPort => $port , Proto => 'tcp' , Timeout => $delay);
# Confirm Connection
if( $socket )
{
print " - Port $port is open\n" ;
}
else
{
# Nothing To Output!
}
}
print "\n===========================================================\n";
# Check if knocking is successful
if ($ssh_port eq "0")
{
# NO SSH PORT REQUIRED
} else {
print "\nChecking SSH port $ssh_port...\n";
if( my $socket = IO::Socket::INET->new(PeerAddr => $target , PeerPort => $ssh_port , Proto => 'tcp' , Timeout => 1 ))
{
print colored ['bold green'], "Port $ssh_port is open\n" ;
}
else
{
print colored ['bold red'], "Port $ssh_port is closed\n" ;
}
}
print "\n\nGo Again? (y/n): ";
my $input = <STDIN>; chomp $input;
if ($input eq "n")
{
goto QUIT
}
else
{
goto START
}
QUIT:
print "\nPress Enter to Exit... ";
while (<>) {
chomp;
last unless length;
}