-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathportchk.tcl
184 lines (179 loc) · 6.28 KB
/
portchk.tcl
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
######################################
## DCC .portchk <host/ip> <port> ##
## PUB !port <host/ip> <port> ##
##.chanset <channel> +portchk ##
######################################
set portchk_setting(flag) ""
set portchk_setting(cmd_pub) "!port"
set portchk_setting(cmd_dcc) "portchk"
set portchk_setting(read) 1
set portchk_setting(onjoin) 1
set portchk_setting(ports) "21 22 23 25 53 80 81 110 113 135 137 138 139 143 443 445 1080 3128 3306 5900 6660 6661 6662 6663 6665 6666 6667 6668 6669 7000 8080 10000 31337 64501 65500 65501"
set portchk_setting(autoban_svr) 0
set portchk_setting(autoban_list) 0
set portchk_setting(global) 0
set portchk_setting(bantime) 5
set portchk_setting(onotice) 1
set portchk_setting(bold) 1
set portchk_setting(portchk:) 1
############################################################################
# PLEASE DO NOT EDIT ANYTHING BELOW UNLESS YOU KNOW WHAT YOU ARE DOING #
############################## Script Begin ################################
#if {![string match 1.8.* $version]} {
# putlog "\002portchk:\002 \002CRITICAL ERROR\002 portchk.tcl requires eggdrop 1.6.x to run."
# die "\002portchk:\002 \002CRITICAL ERROR\002 portchk.tcl requires eggdrop 1.6.x to run."
#}
bind pub $portchk_setting(flag) $portchk_setting(cmd_pub) portchk_scan_pub
bind dcc $portchk_setting(flag) $portchk_setting(cmd_dcc) portchk_scan_dcc
bind join - * portchk_onjoin_scan
setudef flag portchk
proc portchk_dopre {} {
global portchk_setting
if {!$portchk_setting(portchk:)} {
return ""
} elseif {!$portchk_setting(bold)} {
return "portchk: "
} else {
return "\002portchk:\002 "
}
}
proc portchk_onjoin_scan {nick uhost hand chan} {
global portchk_setting
if {($portchk_setting(onjoin)) && ($portchk_setting(ports) != "")} {
foreach i [channel info $chan] {
if {([string match "+portchk" $i]) && ([botisop $chan])} {
set host [lindex [split $uhost @] 1]
foreach p $portchk_setting(ports) {
if {![catch {set sock [socket -async $host $p]} error]} {
set timerid [utimer 15 [list portchk_timeout_join $sock]]
fileevent $sock writable [list portchk_connected_join $nick $chan $sock $host $p $timerid]
}
}
break
}
}
}
}
proc portchk_scan_pub {nick uhost hand chan text} {
global portchk_setting
set host [lindex [split $text] 0]
set port [lindex [split $text] 1]
if {$port == ""} {
putquick "NOTICE $nick :Usage: $portchk_setting(cmd_pub) <host> <port>"
} else {
if {[catch {set sock [socket -async $host $port]} error]} {
putquick "PRIVMSG $chan :15\[portchk4!15\] Connection to $host \($port\) was refused."
} else {
set timerid [utimer 15 [list portchk_timeout_pub $chan $sock $host $port]]
fileevent $sock writable [list portchk_connected_pub $chan $sock $host $port $timerid]
}
}
}
proc portchk_scan_dcc {hand idx text} {
global portchk_setting
set host [lindex [split $text] 0]
set port [lindex [split $text] 1]
if {$port == ""} {
putdcc $idx "[portchk_dopre]Usage: .$portchk_setting(cmd_dcc) <host> <port>"
} else {
if {[catch {set sock [socket -async $host $port]} error]} {
putdcc $idx "[portchk_dopre]Connection to $host \($port\) was refused."
} else {
set timerid [utimer 15 [list portchk_timeout $idx $sock $host $port]]
fileevent $sock writable [list portchk_connected $idx $sock $host $port $timerid]
}
}
}
proc portchk_connected {idx sock host port timerid} {
killutimer $timerid
set error [fconfigure $sock -error]
if {$error != ""} {
close $sock
putdcc $idx "[portchk_dopre]Connection to $host \($port\) failed. \([string totitle $error]\)"
} else {
fileevent $sock writable {}
fileevent $sock readable [list portchk_read $idx $sock $host $port]
putdcc $idx "[portchk_dopre]Connection to $host \($port\) accepted."
}
}
proc portchk_timeout {idx sock host port} {
close $sock
putdcc $idx "[portchk_dopre]Connection to $host \($port\) timed out."
}
proc portchk_read {idx sock host port} {
global portchk_setting
if {$portchk_setting(read)} {
if {[gets $sock read] == -1} {
putdcc $idx "[portchk_dopre]EOF On Connection To $host \($port\). Socket Closed."
close $sock
} else {
putdcc $idx "[portchk_dopre]$host \($port\) > $read"
}
} else {
close $sock
}
}
proc portchk_connected_pub {chan sock host port timerid} {
killutimer $timerid
set error [fconfigure $sock -error]
if {$error != ""} {
close $sock
putquick "PRIVMSG $chan :15\[portchk4!15\] Connection to $host \($port\) failed. \([string totitle $error]\)"
} else {
fileevent $sock writable {}
fileevent $sock readable [list portchk_read_pub $chan $sock $host $port]
putquick "PRIVMSG $chan :15\[portchk4!15\] Connection to $host \($port\) accepted."
}
}
proc portchk_timeout_pub {chan sock host port} {
close $sock
putquick "PRIVMSG $chan :15\[portchk4!15\] Connection to $host \($port\) timed out."
}
proc portchk_connected_join {nick chan sock host port timerid} {
global portchk_setting botnick
killutimer $timerid
set error [fconfigure $sock -error]
if {$error != ""} {
close $sock
} else {
fileevent $sock writable {}
fileevent $sock readable [list portchk_read_join $sock]
if {$portchk_setting(onotice)} {
foreach i [chanlist $chan] {
if {([isop $i $chan]) && ($i != $botnick)} {
putserv "NOTICE $i :Port $port was found open on $nick's host. \($host\)"
}
}
}
if {$portchk_setting(autoban_svr)} {
putserv "MODE $chan +b *!*@$host"
putserv "KICK $chan $nick :One of the ports open on your host is banned."
timer $portchk_setting(bantime) [list portchk_unsvrban $chan $host]
} elseif {$portchk_setting(autoban_list)} {
if {$portchk_setting(global)} {
newban *!*@$host portchk "One of the ports open on your machine is banned." $portchk_setting(bantime)
} else {
newchanban $chan *!*@$host portchk "One of the ports open on your machine is banned." $portchk_setting(bantime)
}
}
}
}
proc portchk_timeout_join {sock} {
close $sock
}
proc portchk_read_join {sock} {
close $sock
}
proc portchk_read_pub {sock} {
global portchk_setting
if {!$portchk_setting(read)} {
close $sock
} elseif {[gets $sock read] == -1} {
putquick "PRIVMSG $chan :EOF On Connection To $host \($port\). Socket Closed."
close $sock
}
}
proc portchk_unsvrban {chan host} {
putserv "MODE $chan -b *!*@$host"
}
putlog "Portchk Addon TCL Modifed By MoBi ? Succesfully Loaded..."