This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Execute shell commands

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
D
DaRkOoO
Halfop
Posts: 67
Joined: Sat Sep 27, 2008 7:27 am

Execute shell commands

Post by DaRkOoO »

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.
r
raider2k
Op
Posts: 140
Joined: Tue Jan 01, 2008 10:42 am

Post by raider2k »

Code: Select all

exec <code-here>
in example

Code: Select all

set testing [exec rm /home/user/test.txt]
putserv "PRIVMSG $chan :$testing"
or

Code: Select all

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.
D
DaRkOoO
Halfop
Posts: 67
Joined: Sat Sep 27, 2008 7:27 am

Post by DaRkOoO »

I dont need something that will execute one specified command..I wanna to I be able to execute whatever command I want..
r
raider2k
Op
Posts: 140
Joined: Tue Jan 01, 2008 10:42 am

Post by raider2k »

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
D
DaRkOoO
Halfop
Posts: 67
Joined: Sat Sep 27, 2008 7:27 am

Post by DaRkOoO »

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..
r
raider2k
Op
Posts: 140
Joined: Tue Jan 01, 2008 10:42 am

Post by raider2k »

Code: Select all

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
D
DaRkOoO
Halfop
Posts: 67
Joined: Sat Sep 27, 2008 7:27 am

Post by DaRkOoO »

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?
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

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: Select all

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.
D
DaRkOoO
Halfop
Posts: 67
Joined: Sat Sep 27, 2008 7:27 am

Post by DaRkOoO »

<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
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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: Select all

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
D
DaRkOoO
Halfop
Posts: 67
Joined: Sat Sep 27, 2008 7:27 am

Post by DaRkOoO »

This one works,thank you..
Post Reply