muhstik- irc flooding solution |
git clone git://git.acid.vegas/muhstik.git |
Log | Files | Refs | Archive | README |
prox.tcl (5933B)
1 # {{{ pub [CS ] SOCKS proxy gathering off phpBB [et al] sources and {DNS,R,...}BL matching 2 array unset {v:sites} {} 3 # {{{ RBL to query 4 set {v:sites:rbl} [list \ 5 rbl.efnet.org \ 6 dnsbl.swiftbl.net \ 7 ircbl.ahbl.org \ 8 dnsbl.dronebl.org \ 9 tor.dnsbl.sectoor.de \ 10 dnsbl.njabl.org] 11 # }}} 12 array unset {v:proxies} 13 array unset {v:proxies:rbl} 14 # {{{ dcsproxy.com 15 array set {v:sites} [list dcsproxy [list \ 16 [list "http://www.dcsproxy.com/login.php?do=login" \ 17 [list \ 18 # vb_login_username "insectcrew" \ 19 vb_login_lusername "szucsy" \ 20 do "login" \ 21 # vb_login_md5password "7e7cb40bdbfd8d4c512eda43e748b3ba" \ 22 vb_login_md5password "966bf1eaaaf07917faa5192115a10988" \ 23 # vb_login_md5password_utf "7e7cb40bdbfd8d4c512eda43e748b3ba" \ 24 vb_login_md5password_utf "966bf1eaaaf07917faa5192115a10988" \ 25 cookieuser 1 \ 26 s "" \ 27 ] \ 28 ] \ 29 "http://www.dcsproxy.com/socks-lists/" \ 30 "http://www.dcsproxy.com/login.php?do=logout" \ 31 {<div>.+?</div>} \ 32 {<a href="(.+?)"} \ 33 ]] 34 # }}} 35 # {{{ proxy-heaven.blogspot.com 36 array set {v:sites} [list proxy-heaven [list \ 37 [list] \ 38 "http://proxy-heaven.blogspot.com/" \ 39 "" \ 40 {<h3 class=.+?>.+?</h3>} \ 41 {(?i)href='(.+?socks.+?)'} \ 42 ]] 43 # }}} 44 set {v:filter} {:23|443|(?:[18]0)?8[08]|312[78]|6588|9050$} 45 # }}} 46 # {{{ pub [CS ] SOCKS proxy gathering off phpBB [et al] sources and {DNS,R,...}BL matching 47 setudef flag socks 48 array unset {v%cookies} 49 50 # {{{ bind evnt -|- loaded v%socks:ini 51 bind evnt -|- loaded v%socks:ini 52 proc v%socks:ini args { 53 global {v:sites} 54 foreach {- - tid} \ 55 [join [lsearch -all -inline -regexp [utimers] {v%socks:daily}]] { 56 killutimer ${tid} } 57 foreach t [array names {v:sites}] { 58 foreach c [channels] { 59 if {![channel get ${c} socks]} { continue } 60 catch {utimer 86400 [list v%socks:daily ${c} ${t}]} ;# XXX tunable 61 } 62 } 63 } 64 # }}} 65 # {{{ utimer 86400 [list v%socks:daily [ ... ]] 66 proc v%socks:daily {c t} { 67 catch {v:socks * * * ${c} ${t}} 68 utimer 86400 [list v%socks:daily ${c} ${t}] 69 } 70 # }}} 71 # {{{ bind pub S|- .socks v:socks 72 bind pub S|- .socks v:socks 73 proc v:socks {n u h c t} { 74 global {v:sites} {v:proxies} {v:filter} {v%cookies} 75 if {![channel get ${c} socks]} { return } 76 if {![string length [set site [last [array get {v:sites} ${t}]]]]} { 77 v%blog "[v%ifx johne] unknown site `${t}'" ${c}; return } 78 79 set llogin [lindex ${site} 0]; set turl [lindex ${site} 1]; set lourl [lindex ${site} 2] 80 set tp0 [lindex ${site} 3]; set tp1 [lindex ${site} 4] 81 if { [llength ${llogin}] && \ 82 ![string length [last [array get {v%cookies} ${site}]]]} { 83 set lurl [lindex ${llogin} 0]; set lbody [lindex ${llogin} 1] 84 v%fetch -cookies POST ${t} ${lurl} ${lbody} } 85 86 set socks {} 87 foreach thr [regexp -all -inline ${tp0} [v%fetch -- GET ${t} ${turl}]] { 88 if {[regexp -- ${tp1} ${thr} {} thrurl]} { 89 set thtml [v%fetch -- GET ${t} ${turl}] 90 foreach {- s} [regexp -all -inline {\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+} ${thtml}] { 91 lappend socks ${s} 92 } 93 } 94 } 95 96 set socks [lsearch -not -all -inline -regexp ${socks} ${v:filter}] 97 if {![llength ${socks}]} { v%blog "[v%ifx johne/${t}] No socks found. FML" ${c} }\ 98 else { v%blog "[v%ifx johne/${t}] Done. [llength ${socks}] socks found." ${c} } 99 array set {v:proxies} [list ${t} ${socks}] 100 if {[string length ${lourl}]} { catch {v%fetch -cookies GET ${lourl}}; } 101 return 1 102 } 103 # }}} 104 # {{{ bind pub S|- .matchbl v:socks:matchbl 105 bind pub S|- .matchbl v:socks:matchbl 106 proc v:socks:matchbl {n u h c t {zidx 0}} { 107 global {v:proxies} {v:proxies:rbl} {v:sites:rbl} 108 if {![channel get ${c} socks]} { return } 109 if {${zidx} == 0} { array set {v:proxies:rbl} [list ${t} [concat [last [array get {v:proxies} ${t}]]]] } 110 if {![llength [set proxies [last [array get {v:proxies:rbl} ${t}]]]]} { 111 v%blog "[v%ifx johne/rbl] don't have n e proxies for `${t}'" ${c}; return } 112 113 if {![string length [set zone [lindex ${v:sites:rbl} ${zidx}]]]} { return } 114 set nproxies [llength ${proxies}]; set n 0 115 v%blog "[v%ifx johne/rbl] ${t}: Matching ${nproxies} proxies against ${zone}" ${c} 116 array set {v:proxies:rbl} [list ${t} {}] 117 foreach ip ${proxies} { 118 incr n 119 if {[catch {set ha [apply format [join [list %d.%d.%d.%d [lreverse [scan ${ip} %d.%d.%d.%d]]]]].${zone}}] != 0} { 120 if {${n} >= ${nproxies}} { 121 v%dns:rbl - - - ${c} ${t} - ${zone} [incr zidx] [list ${n} ${h} ${u} ${c} ${t}] 122 } 123 } elseif {${n} >= ${nproxies}} { 124 dnslookup ${ha} \ 125 v%dns:rbl ${c} ${t} ${ip} ${zone} [incr zidx] \ 126 [list ${n} ${h} ${u} ${c} ${t}] 127 } else { dnslookup ${ha} v%dns:rbl ${c} ${t} ${ip} } 128 } 129 } 130 # }}} 131 132 # {{{ Ancillary 133 proc v%fetch {{cookies ""} {method ""} site url {body ""}} { 134 global {v%cookies} 135 set method [string tolower ${method}] 136 set cookie [last [array get {v%cookies} ${site}]] 137 # N.B. Tcl is the most worthless language there is 138 set html [apply ::httpx::${method} \ 139 [list -headers ${url} [list Cookie [list ${cookie}]] ${body}]] 140 set status [lindex ${html} 0] 141 142 if {[string first 20 ${status} 0] != 0 && \ 143 [string first 30 ${status} 0] != 0} { return -code return } ;# TODO 144 if {${cookies} == "-cookies"} { 145 set hdr [lindex ${html} 1]; set cookies "" 146 foreach idx [lsearch -all -regexp ${hdr} {Set-Cookie}] { 147 append cookies "[lindex ${hdr} [expr ${idx} + 1]]; " 148 }; if {[string length ${cookies}]} { 149 array set {v%cookies} [list ${site} ${cookies}] } 150 }; last ${html} 151 } 152 153 proc v%dns:rbl {ip host s c t oip {zone ""} {last 0} {pargs ""}} { 154 global {v:proxies:rbl} 155 if {${last}} { 156 v%dns:rbl:fini ${t} ${c} ${zone}; v:socks:matchbl - - - ${c} ${t} ${last} 157 } elseif {!${s}} { array set {v:proxies:rbl} [list ${t} [concat [last [array get {v:proxies:rbl} ${t}]] ${oip}]] } 158 } 159 160 proc v%dns:rbl:fini {t c zone} { 161 global {v:proxies:rbl} 162 set n [llength [last [array get {v:proxies:rbl} ${t}]]] 163 v%blog "[v%ifx johne/rbl] ${t}!${zone}: ${n} unlisted." ${c} 164 } 165 # }}} 166 # }}} 167 # }}}