| View previous topic :: View next topic |
| Author |
Message |
DaRkOoO Halfop
Joined: 27 Sep 2008 Posts: 67
|
Posted: Sun Apr 26, 2009 3:54 pm Post subject: Execute shell commands |
|
|
Hi all,
I was wondering is there any script/module which will execute some shell command and say what it got on IRC.I saw people using .tcl exe ls /home/ ,so it is possible..I didnt found anything,except EggShell..But when I tried it,he leave every command active on shell and that process die when I kill egg..So I had problem with fork when I was using it..Is there any other solution?Maybe writing new tcl script?
Cheers,
Darko. |
|
| Back to top |
|
 |
raider2k Op
Joined: 01 Jan 2008 Posts: 140
|
Posted: Mon Apr 27, 2009 12:16 am Post subject: |
|
|
in example
| Code: |
set testing [exec rm /home/user/test.txt]
putserv "PRIVMSG $chan :$testing"
|
or
| Code: |
set testing2 [exec some.sh]
putserv "PRIVMSG $chan :$testing2"
|
depends on what exactly you are trying to do, supply more information please. also there is more than just one way to get things done but - like i said - depends on what you are trying to do. |
|
| Back to top |
|
 |
DaRkOoO Halfop
Joined: 27 Sep 2008 Posts: 67
|
Posted: Mon Apr 27, 2009 9:13 am Post subject: |
|
|
| I dont need something that will execute one specified command..I wanna to I be able to execute whatever command I want.. |
|
| Back to top |
|
 |
raider2k Op
Joined: 01 Jan 2008 Posts: 140
|
Posted: Mon Apr 27, 2009 9:28 am Post subject: |
|
|
| then please supply enough information to have something to work on since the information you left in this post is not enough in my opinion |
|
| Back to top |
|
 |
DaRkOoO Halfop
Joined: 27 Sep 2008 Posts: 67
|
Posted: Mon Apr 27, 2009 10:48 am Post subject: |
|
|
| What kind of informations you need?I simply want to bot react for example on !shell ls /home/ or !shell rm bla.txt or !shell uptime etc..He should just say result of that command on IRC channel.. |
|
| Back to top |
|
 |
raider2k Op
Joined: 01 Jan 2008 Posts: 140
|
Posted: Tue Apr 28, 2009 12:38 am Post subject: |
|
|
| Code: |
bind pub - !shell shellcommand
proc shellcommand { nick uhost handle chan text } {
set docmd [exec $text]
putserv "PRIVMSG $chan :$docmd"
}
|
is the easiest and simplest way of it all
just try and also notice that you wont be able at all to have a kind of shell-replacement |
|
| Back to top |
|
 |
DaRkOoO Halfop
Joined: 27 Sep 2008 Posts: 67
|
Posted: Tue Apr 28, 2009 8:10 am Post subject: |
|
|
It works,but..
<DaRkOoO> !shell ls /home/
<DaRkOoO> !shell ls
<Genije> Genije.chan
[14:01] Tcl error [shellcommand]: couldn't execute "ls /home": no such file or directory
He paste just one line,never more..For example !shell who,he will paste just first line and then stop..Can that be fixed? |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Tue Apr 28, 2009 4:48 pm Post subject: |
|
|
| DaRkOoO wrote: | It works,but..
<snipped irrelevant parts>
He paste just one line,never more..For example !shell who,he will paste just first line and then stop..Can that be fixed? |
| Code: | bind pub mn|- !shell shellcommand
proc shellcommand { nick uhost handle chan text } {
set result [exec [list $text]]
if {[string llength $result]} {
foreach line [split $result "\n"] {
putserv "PRIVMSG $chan :$line"
}
}
} |
Simply incorporate a foreach to split the result on newline, and putserv each line. Also changed that pub bind to only accept input from global owners or masters of your bot as well as adding list to the exec statement to avoid double substitution. _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
DaRkOoO Halfop
Joined: 27 Sep 2008 Posts: 67
|
Posted: Wed Apr 29, 2009 7:16 am Post subject: |
|
|
<DaRkOoO> !shell ls
<DaRkOoO> !shell uptime
[13:09] Tcl error [shellcommand]: couldn't execute "{ls }": no such file or directory
[13:09] Tcl error [shellcommand]: unknown or ambiguous subcommand "llength": must be bytelength, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, reverse, tolower, totitle, toupper, trim, trimleft, trimright, wordend, or wordstart |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Wed Apr 29, 2009 8:37 am Post subject: |
|
|
Actually, there is no double substitution issues with exec, so the list construct should be removed. Also, each parameter passed to exec is used as an individual parameter for the shell commandline, where the first parameter becomes the command (others depend on pipelining and redirections). As such, the current code will not allow for any parameters being sent to the shell command; ie "ls" will work, but "ls /home/" will not, as there is no binary known as "ls\ \/home\/".
This code should take care of the above mentioned issues. I would however like to emphasize the danger of providing means of remote code execution in this manner, as this could easily get your whole shell-account compromised by anyone simply matching any +n user record.
| Code: | bind pub n !shell shellcommand
proc shellcommand {nick host handle channel text} {
set cmdline [split $text]
if {[catch {eval [linsert $cmdline 0 "exec"]} status]} {
puthelp "PRIVMSG $channel :Executed \"$text\" returned error status:"
foreach line [split $status "\n"] {
puthelp "PRIVMSG $channel :$line"
}
puthelp "PRIVMSG $channel :errorInfo:"
foreach line [split $::errorInfo "\n"] {
puthelp "PRIVMSG $channel :$line"
}
} {
puthelp "PRIVMSG $channel :Executed \"$text\" returned ok status:"
foreach line [split $status "\n"] {
puthelp "PRIVMSG $channel :$line"
}
}
} |
_________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
DaRkOoO Halfop
Joined: 27 Sep 2008 Posts: 67
|
Posted: Wed Apr 29, 2009 8:47 am Post subject: |
|
|
| This one works,thank you.. |
|
| Back to top |
|
 |
|