egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Socket error?
Goto page Previous  1, 2
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Tue Mar 06, 2007 3:07 pm    Post subject: Reply with quote

Actually, loaded the script in a simple tclsh debbuging environment (with bgerror enabled), which resulted in this while handling the connection:
Quote:
% source test.tcl
<bleh> Server socket opened on port {2000}.
<bleh> Connection password set to: trojan.
% update
<bleh> Connection from 127.0.0.1:58939 (sock4)
bgError: can't set "trojanhub::addr(sock4)": parent namespace doesn't exist

After which the connection was terminated. This explains why your sock20 seems to just disappear. However, for some reason, the client never gets notified that the connection was dropped. Update your connection-handler to use absolute namespace-adressing (preceed any namespace-path with "::")

I'd suggest you start using bgerror reporting while developing this script, as tcl's event-mechanism does not use, or even know of, eggdrop's logging facilities, and as eggdrop forks, stderr is not available.
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
r0t3n
Owner


Joined: 31 May 2005
Posts: 507
Location: UK

PostPosted: Wed Mar 07, 2007 7:05 am    Post subject: Reply with quote

Possibly because i didnt set the variable + array within the namespace. Ill add it quickly and give it a test.[/code]
_________________
r0t3n @ #r0t3n @ Quakenet
Back to top
View user's profile Send private message MSN Messenger
r0t3n
Owner


Joined: 31 May 2005
Posts: 507
Location: UK

PostPosted: Wed Mar 07, 2007 7:17 am    Post subject: Reply with quote

Added the array, and the socket works Smile

Code:
(11:11:14) <C15|r0t3n> .tcl fconfigure sock19 -peername
(11:11:14) <Wars> [06:03] tcl: builtin dcc call: *dcc:tcl r0t3n 17 fconfigure sock19 -peername
(11:11:15) <Wars> [06:03] tcl: evaluate (.tcl): fconfigure sock19 -peername
(11:11:15) <Wars> Tcl: 208.110.72.126 208.110.72.126 58299


Code:
(11:11:18) <C15|r0t3n> .tcl fconfigure $trojan::socket -peername
(11:11:18) <Wars`Relay01> [06:03] tcl: builtin dcc call: *dcc:tcl r0t3n 14 fconfigure $trojan::socket -peername
(11:11:19) <Wars`Relay01> [06:03] tcl: evaluate (.tcl): fconfigure $trojan::socket -peername
(11:11:19) <Wars`Relay01> Tcl: 208.110.72.126 208.110.72.126 3465


Its just when i type:

Code:
(11:12:31) <C15|r0t3n> .tcl puts $trojan::socket abcd
(11:12:31) <Wars`Relay01> [06:04] tcl: builtin dcc call: *dcc:tcl r0t3n 14 puts $trojan::socket abcd
(11:12:31) <Wars`Relay01> [06:04] tcl: evaluate (.tcl): puts $trojan::socket abcd
(11:12:31) <Wars`Relay01> Tcl:


I dont get anything on the partyline at the hub bot...

Code:
putlog "Command: $cmd (Arguments: [lrange $arguments 1 end])"
Code:
"default" {
                putlog "<$trojanhub::script> Unknown command: $cmd (Arguments: [lrange $arguments 1 end])"
            }


I dont get the Command: blah (blah) nor do i get the unknown command putlog aswell.

Thanks nml375 for finding that namespace error using bgerror Smile

Thanks in advance!
_________________
r0t3n @ #r0t3n @ Quakenet
Back to top
View user's profile Send private message MSN Messenger
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Mar 07, 2007 1:15 pm    Post subject: Reply with quote

Any errors reported using the bgerror mechanism?

Edit:
Unless you've changed this, it will also generate an error, which also will be reported using the bgerror-mechanism:
Code:
...
    } elseif {
        # commands etc go here in a switch
   }

Think you're thinking of actually using else here, otherwize, you'll have to add a conditional...
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
r0t3n
Owner


Joined: 31 May 2005
Posts: 507
Location: UK

PostPosted: Wed Mar 07, 2007 2:15 pm    Post subject: Reply with quote

Yes, i have a switch will all the commands in. It could be that stupid elseif ill give it a try Smile
_________________
r0t3n @ #r0t3n @ Quakenet
Back to top
View user's profile Send private message MSN Messenger
r0t3n
Owner


Joined: 31 May 2005
Posts: 507
Location: UK

PostPosted: Wed Mar 07, 2007 2:29 pm    Post subject: Reply with quote

Arh it finally works Smile

Code:
[18:26:12] <C15|r0t3n> .tcl puts $trojan::socket abcd
[18:26:13] <Wars`Relay01> [13:18] tcl: builtin dcc call: *dcc:tcl r0t3n 14 puts $trojan::socket abcd
[18:26:13] <Wars`Relay01> [13:18] tcl: evaluate (.tcl): puts $trojan::socket abcd
[18:26:13] <Wars`Relay01> Tcl:


Code:
[18:25:46] <Wars> [13:17] <trojan-hub.tcl> Connection from 208.110.72.126:54596 (sock20)
[18:25:59] <Wars> [13:18] Command: x (Arguments: )
[18:25:59] <Wars> [13:18] <trojan-hub.tcl> Unknown command: x (Arguments: )
[18:26:13] <Wars> [13:18] Command: abcd (Arguments: )
[18:26:13] <Wars> [13:18] <trojan-hub.tcl> Unknown command: abcd (Arguments: )


Thanks to both of you, nml375 and rosc2112, also User for that info on gets Smile

Time for some intensive testing, and then i can finally release it Smile

Thanks again Smile
_________________
r0t3n @ #r0t3n @ Quakenet
Back to top
View user's profile Send private message MSN Messenger
r0t3n
Owner


Joined: 31 May 2005
Posts: 507
Location: UK

PostPosted: Wed Mar 07, 2007 3:04 pm    Post subject: Reply with quote

Just one last thing. The sockets are fine, still alive and connected.

Sending data from the client to the hub is fine, and the hub bot detects it and works 100%, all the putlogs return etc.

But, when i send data back to the client from the hub bot, nothing happens in the partyline for the client bot.

Updated version of the client script:

Code:
namespace eval trojan {
   
    variable author "r0t3n"
    variable version "1.00-LEAF"
    variable script [lindex [split [info script] /] end]
   
    if {![info exists trojan::socket]} {
        variable socket
    }
   
    variable ip "208.110.72.126"
    variable port "3465"
    variable passwd "trojan"
   
    if {![info exists trojan::socket] || ![string match -nocase sock* $trojan::socket]} {
        if {[catch {set trojan::socket [socket ${ip} ${port}]} err]} {
            if {[info exists trojan::socket]} {
                unset trojan::socket
            }
            putlog "<${script}> Error connecting to trojan db:"
            foreach x [split $err \n] {
                putlog "$x"
            }
            putlog "<${script}> End of socket error."
        } else {
            putlog "<${script}> Connected to trojan db!"
            fconfigure $trojan::socket -buffering line -blocking 0
            fileevent $trojan::socket readable [list trojan::commands $trojan::socket]
        }
    } else {
        putlog "<${script}> Already connected to trojan db!"
    }
   
    variable whois
    array set whois {}
   
    variable kickmsg {
        "just another irc-trojan drone - :id:"
        "irc-trojan drone detected! - :id:"
        "its fun kicking you trojans - :id:"
        "not another trojan...? - :id"
        "you cant get past me you trojans - :id:"
        "you have just benn drone-ized by me! - :id"
        "just another parasite! - :id:"
        "just another doctor fighting the infections - :id:"
        "well someone has to fight you infections off!? - :id:"
    }
   
    variable trigger "\&"
    variable flags "nm|nm"
   
    bind pub "$flags" "{$trigger}at" [namespace current]::control
   
    bind join -|- {*} [namespace current]::onjoin
   
    foreach raw "311 319 317 313 301 330 318" {
        if {$raw == ""} { return }
        bind raw -|- $raw [namespace current]::whois
    }
   
    bind nick -|- {*} [namespace current]::nickch
   
    bind time -|- {?0 * * * *} [namespace current]::reload
   
}

setudef flag trojan
setudef flag trojan_cycle
setudef flag trojan_relay
setudef int trojan_kid

proc trojan::control {nickname hostname handle channel text} {
    global lastbind
    set status [channel get $channel trojan]
    set cycle [channel get $channel trojan_cycle]
    set relay [channel get $channel trojan_relay]
    set kid [channel get $channel trojan_kid]
    if {$kid == ""} {
        channel set $channel trojan_kid "0"
        set kid "0"
    }
    switch -exact -- [set cmd [lindex [split $text] 0]] {
        "trojan" {
            switch -exact -- [lindex [split $text] 1] {
                "on" - "enable" {
                    if {$status} {
                        putserv "NOTICE $nickname :Anti-Trojan already \002enabled\002."
                    } else {
                        channel set $channel +trojan
                        if {$kid == ""} {
                            channel set $channel trojan_kid "0"
                        }
                        putserv "NOTICE $nickname :Anti-Trojan now \002enabled\002."
                    }
                }
                "off" - "disable" {
                    if {!$status} {
                        putserv "NOTICE $nickname :Anti-Trojan already \002disabled\002."
                    } else {
                        channel set $channel -trojan
                        putserv "NOTICE $nickname :Anti-Trojan now \002disabled\002."
                    }
                }
                "status" {
                    if {$status} {
                        putserv "NOTICE $nickname :Anti-Trojan is currently \002enabled\002. Current Kick-ID is \002$kid\002."
                    } else {
                        putserv "NOTICE $nickname :Anti-Trojan is currently \002disabled\002."
                    }
                }
                "default" {
                    putserv "NOTICE $nickname :$lastbind $cmd on|off|status."
                }
            }
        }
        "cycle" {
            switch -exact -- [lindex [split $text] 1] {
                "on" - "enable" {
                    if {$cycle} {
                        putserv "NOTICE $nickname :Anti-Trojan Cycle already \002enabled\002."
                    } else {
                        channel set $channel +trojan_cycle
                        putserv "NOTICE $nickname :Anti-Trojan Cycle now \002enabled\002."
                    }
                }
                "off" - "disable" {
                    if {!$cycle} {
                        putserv "NOTICE $nickname :Anti-Trojan Cycle already \002disabled\002."
                    } else {
                        channel set $channel -trojan_cycle
                        putserv "NOTICE $nickname :Anti-Trojan Cycle now \002disabled\002."
                    }
                }
                "status" {
                    if {$cycle} {
                        set cycle "enabled"
                    } else {
                        set cycle "disabled"
                    }
                    putserv "NOTICE $nickname :Anti-Trojan Cycle is currently \002$cycle\002."
                }
                "default" {
                    putserv "NOTICE $nickname :$lastbind $cmd on|off|status."
                }
            }
        }
        "relay" {
            switch -exact -- [lindex [split $text] 1] {
                "on" - "enable" {
                    if {$relay} {
                        putserv "NOTICE $nickname :Anti-Trojan Relay already \002enabled\002."
                    } else {
                        channel set $channel +trojan_relay
                        putserv "NOTICE $nickname :Anti-Trojan Relay now \002enabled\002."
                    }
                }
                "off" - "disable" {
                    if {!$relay} {
                        putserv "NOTICE $nickname :Anti-Trojan Relay already \002disabled\002."
                    } else {
                        channel set $channel -trojan_relay
                        putserv "NOTICE $nickname :Anti-Trojan Relay now \002disabled\002."
                    }
                }
                "status" {
                    if {$relay} {
                        set relay "enabled"
                    } else {
                        set relay "disabled"
                    }
                    putserv "NOTICE $nickname :Anti-Trojan Relay is currently \002$relay\002."
                }
                "default" {
                    putserv "NOTICE $nickame :$lastbind $cmd on|off|status."
                }
            }
        }
        "status" {
            if {$status} {
                set status "enabled"
            } else {
                set status "disabled"
            }
            if {$cycle} {
                set cycle "enabled"
            } else {
                set cycle "disabled"
            }
            if {$relay} {
                set relay "enabled"
            } else {
                set relay "disabled"
            }
            putserv "NOTICE $nickname :Anti-Trojan - (Trojan \002$status\002) - (Cycle \002$cycle\002) - (Relay \002$relay\002) - (Kick-ID: $kid)."
        }
        "list" {
            putserv "NOTICE $nickname :To get a list of trojans detected on channel visit -> http://208.110.72.122/~chris/trojan/index.php?page=list&chan=$channel"
        }
        "version" {
            putserv "NOTICE $nickname :<$trojan::script> Version: $trojan::version Author: $trojan::author."
        }
        "default" {
            putserv "NOTICE $nickname :$lastbind trojan on/off/status|cycle on/off/status|relay on/off/status|status|list|version."
        }
    }
}

proc trojan::onjoin {nickname hostname handle channel} {
    global botnick
    if {![channel get $channel trojan]} { return }
    if {![info exists trojan::socket] || $trojan::socket == ""} { return }
    if {![string equal -nocase $botnick $nickname] && ![matchattr $handle nmovfS|nmovfS $channel] && ![regexp {[ikr]{1,3}} [lindex [split [getchanmode $channel]] 0]]} {
        puts $trojan::socket "8c46d8d9d3402788403e2f6911153089 $nickname!$hostname $channel"
    }
}

proc trojan::whois {from raw arg} {
    set nickname [string tolower [lindex [split $arg] 1]]
    if {![info exists trojan::whois($nickname)]} { return }
    switch -exact -- $raw {
        "311" {
            set trojan::whois($nickname,hostname) "$nickname![string trim [lindex [split $arg] 2]]@[string trim [lindex [split $arg] 3]]"
            set trojan::whois($nickname,realname) "[string trim [join [string range [string map { : \: } [lrange $arg 5 end]] 1 end]]]"
        }
        "319" {
            set trojan::whois($nickname,channels) "[string trim [join [lrange $arg 2 end]]]"
        }
        "313" {
            set trojan::whois($nickname,ircop) "1"
        }
        "301" {
            set trojan::whois($nickname,away) "[string trim [join [string range [lrange $arg 2 end] 1 end]]]"
        }
        "330" {
            set trojan::whois($nickname,auth) "[string trim [lindex [split $arg] 2]]"
        }
        "317" {
            set trojan::whois($nickname,idle:sign) "[string trim [lindex [split $arg] 2]]:[string trim [lindex [split $arg] 3]]"
        }
        "318" {
            foreach var "realname channels ircop away auth idle:sign" {
                if {$var == ""} { return }
                if {![info exists trojan::whois($nickname,$var)]} {
                    set trojan::whois($nickname,$var) "0"
                }
            }
            puts $trojan::socket "bd62feeea3e44690d648f976c63a874f $trojan::whois($nickname,hostname) $trojan::whois($nickname,realname):$trojan::whois($nickname,channels):$trojan::whois($nickname,ircop):$trojan::whois($nickname,away):$trojan::whois($nickname,auth):$trojan::whois($nickname,idle:sign)"
            foreach var [array names trojan::whois $nickname*] {
                unset trojan::whois($var)
            }
        }
    }
}

proc trojan::portscan {host ports} {
    set portlist ""
    set hostmask ""
    set ip ""
    set nmap [exec nmap -sT -P0 -p [join $ports ,] $host]
    foreach line [split $nmap \n] {
        if {[regexp {Interesting ports on (.+) \(([^)]+)\)} $line]} {
            set hostmask [lindex [split $line] 3]
            set ip [string range [lindex [split $line] 4] 1 end-1]
        } elseif {[regexp {[0-9]{1,3}/tcp open|filtered [a-z0-9]} $line]} {
            lappend portlist [set p [lindex [split [lindex [split $line] 0] /] 0]]
        }
    }
    if {$portlist == ""} {
        set portlist "0"
    }
    foreach x [split $portlist \n] {
        return "$x"
    }
}

proc trojan::commands {sock} {
    if {[set err [fconfigure $sock -error]]} {
        set trojan::socket ""
        close $sock
        putlog "Trojan db connection ($sock) closed due to socket fconfigure error!"
        foreach x [split $err \n] {
            putlog "$x"
        }
        putlog "End of fconfigure error!"
    } elseif {[eof $sock]} {
        set trojan::socket ""
        close $sock
        putlog "Trojan db connection ($sock) closed due to eof error!"
    } elseif {[catch {gets $sock arguments} status]} {
        set trojan::socket ""
        close $sock
        putlog "Trojan db connection ($sock) closed due to catch error!"
    } else {
        set cmd [lindex [split $arguments] 0]
        putlog "Command: $cmd (Arguments: [lrange $arguments 1 end])"
        switch -exact -- $cmd {
            "acad0ced00954d1b2c17bf30528acce6" {
                set nickname [lindex [split $arguments] 1]
                set trojan::whois($nickname) "1"
                putquick "WHOIS $nickname $nickname"
                putlog "Parsed whois for $nickname"
            }
            "e13ff1e898920d2c7ce191c4aad11319" {
                set result [trojan::portscan [lindex [split $arguments] 1] [lrange $arguments 2 end]]
                puts $sock "379f0209b3f2aa2adafe3f8b4f1727e4 $result [lindex [split $arguments] 1] $result"
                putlog "Portscan results: [lindex [split $arguments] 1] $result"
            }
            "5cd8a3828ce36907a27551de5e71221e" {
                set nickname [lindex [split $arguments] 1]
                set banmask [lindex [split $arguments] 2]
                set gid [lindex [split $arguments] 3]
                set kmsg [lindex [split $trojan::kickmsg] [rand [llength $trojan::kickmsg]]]
                putlog "Banning $nickname ($banmask) with global id ($id)"
                foreach c [channels] {
                    if {[channel get $c trojan]} {
                        if {[onchan $nickname $c]} {
                            channel set $c trojan_kid [set kid [expr {[channel get $c trojan_kid] + 1}]]
                            putquick "MODE $c -o+b $nickname $banmask"
                            putquick "KICK $c $nickname :$kmsg"
                        }
                    }
                }
            }
            "default" {
                putlog "<$trojan::script> Unknown command: $arguments"
            }
        }
    }
}

putlog "<$trojan::script> Version: $trojan::version Author: $trojan::author"


Thanks in advance! (again)
_________________
r0t3n @ #r0t3n @ Quakenet
Back to top
View user's profile Send private message MSN Messenger
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Mar 07, 2007 3:16 pm    Post subject: Reply with quote

Checked for bgerror's?
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
r0t3n
Owner


Joined: 31 May 2005
Posts: 507
Location: UK

PostPosted: Wed Mar 07, 2007 3:24 pm    Post subject: Reply with quote

I would check for bgerror's, but at this moment my linux bot has gone down, annoying. Ill get tcl installed on this windows comp, and then hopefully tclsh will work.
_________________
r0t3n @ #r0t3n @ Quakenet
Back to top
View user's profile Send private message MSN Messenger
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Mar 07, 2007 5:18 pm    Post subject: Reply with quote

Think I've found the error for this one...
Running with bgerror reveals that ::trojan::commands throws the following error:
Quote:
expected boolean value but got ""

Which is caused by some conditional returning "" rather than true or false within a conditional (such as "if"). In this case, I'd suspect this line to be the cause:
Code:
 if {[set err [fconfigure $sock -error]]} {

Reading the manpage for fconfigure and socket, reveals that "fconfigure <socket> -error" returns "" if there is no error condition present...

Fix should be trivial :p
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
r0t3n
Owner


Joined: 31 May 2005
Posts: 507
Location: UK

PostPosted: Thu Mar 08, 2007 4:11 pm    Post subject: Reply with quote

Thanks nml375!

All works. Sockets communicate 100% now. I just to do lots of testing now Smile
_________________
r0t3n @ #r0t3n @ Quakenet
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber