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 

Execute shell commands

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
DaRkOoO
Halfop


Joined: 27 Sep 2008
Posts: 67

PostPosted: Sun Apr 26, 2009 3:54 pm    Post subject: Execute shell commands Reply with quote

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
View user's profile Send private message
raider2k
Op


Joined: 01 Jan 2008
Posts: 140

PostPosted: Mon Apr 27, 2009 12:16 am    Post subject: Reply with quote

Code:

exec <code-here>


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
View user's profile Send private message
DaRkOoO
Halfop


Joined: 27 Sep 2008
Posts: 67

PostPosted: Mon Apr 27, 2009 9:13 am    Post subject: Reply with quote

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
View user's profile Send private message
raider2k
Op


Joined: 01 Jan 2008
Posts: 140

PostPosted: Mon Apr 27, 2009 9:28 am    Post subject: Reply with quote

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
View user's profile Send private message
DaRkOoO
Halfop


Joined: 27 Sep 2008
Posts: 67

PostPosted: Mon Apr 27, 2009 10:48 am    Post subject: Reply with quote

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
View user's profile Send private message
raider2k
Op


Joined: 01 Jan 2008
Posts: 140

PostPosted: Tue Apr 28, 2009 12:38 am    Post subject: Reply with quote

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
View user's profile Send private message
DaRkOoO
Halfop


Joined: 27 Sep 2008
Posts: 67

PostPosted: Tue Apr 28, 2009 8:10 am    Post subject: Reply with quote

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
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Tue Apr 28, 2009 4:48 pm    Post subject: Reply with quote

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
View user's profile Send private message
DaRkOoO
Halfop


Joined: 27 Sep 2008
Posts: 67

PostPosted: Wed Apr 29, 2009 7:16 am    Post subject: Reply with quote

<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
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Apr 29, 2009 8:37 am    Post subject: Reply with quote

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
View user's profile Send private message
DaRkOoO
Halfop


Joined: 27 Sep 2008
Posts: 67

PostPosted: Wed Apr 29, 2009 8:47 am    Post subject: Reply with quote

This one works,thank you..
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
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