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.

NMAP

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
m
mimizu
Voice
Posts: 7
Joined: Wed Feb 20, 2013 4:14 am

NMAP

Post by mimizu »

bind pub - !nmap port_scan
proc port_scan {nick uhost handle chan args} {
putserv "PRIVMSG $chan : Scanning...... $args wait................!!"
global data_var
set data_var [exec nmap $args]
set l [split $data_var "\r\n"]
foreach i $l { puthelp "PRIVMSG $chan : $i " }
putlog "<<$chan>> !$handle! !nmap"
}
please help, to fix nmap script above.

if anyone did order !nmap nmap it will wait for the process is complete and can not process !nmap with a message on the channel "please wait a moment, are doing nmap"


Please help.

thank you
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

Try this

Code: Select all

bind pub - !nmap port_scan

proc port_scan {nick uhost handle chan args} {
	global progress

	if {[info exists progress]} { putserv "PRIVMSG $chan :nmap in progress please wait to finish.."; return }

	putserv "PRIVMSG $chan : Scanning...... $args wait................!!"

	set progress 1

	set data_var [exec nmap $args]

	set l [split $data_var "\r\n"]

	foreach i $l { puthelp "PRIVMSG $chan : $i " }

	set progress 0

	putlog "<<$chan>> !$handle! !nmap"
}
d
dirty
Halfop
Posts: 40
Joined: Fri Feb 08, 2013 2:33 pm
Location: Romania
Contact:

Post by dirty »

And maybe add some protection so that it won`t scan if someone uses !nmap without any $args

Code: Select all

bind pub - !nmap port_scan 

proc port_scan {nick uhost handle chan args} { 
   global progress 
   
   if {$args == ""} { putserv "PRIVMSG $chan :Error. No arguments specified."; return }
   if {[info exists progress]} { putserv "PRIVMSG $chan :nmap in progress please wait to finish.."; return } 

   putserv "PRIVMSG $chan : Scanning...... $args wait................!!" 
   putlog "<<$chan>> !$handle! !nmap"

   set progress 1 

   set data_var [exec nmap $args] 

   set l [split $data_var "\r\n"] 

   foreach i $l { puthelp "PRIVMSG $chan : $i " } 

   set progress 0  
} 
come to the dark side.. I have cookies!
WwW.BotZone.TK
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Public access to exec.. bad idea in the first place. :shock:

Not to mention the info exists progress will work for the first time, then will not allow the script to continue.

I think you meant to create an global variable outside the port_scan proc (after bind line, like set progress 0) then match it's value against 1 or 0 like if {$progress} or if {!$progress} and proceed with return or continue. Oh, and guys please refrain from using $args as has special meaning in TCL.
Once the game is over, the king and the pawn go back in the same box.
d
dirty
Halfop
Posts: 40
Joined: Fri Feb 08, 2013 2:33 pm
Location: Romania
Contact:

Post by dirty »

Not really caesar.. could be done this way..

Code: Select all

bind pub - !nmap port_scan 

proc port_scan {nick uhost handle chan text} { 
   global progress 
    
   if {$text == ""} { putserv "PRIVMSG $chan :Error. No arguments specified."; return } 
   if {[info exists progress]} { putserv "PRIVMSG $chan :nmap in progress please wait to finish.."; return } 

   putserv "PRIVMSG $chan : Scanning...... $text wait................!!" 
   putlog "<<$chan>> !$handle! !nmap" 

   set progress 1 

   set data_var [exec nmap $text] 

   set l [split $data_var "\r\n"] 

   foreach i $l { puthelp "PRIVMSG $chan : $i " } 

   unset -nocomplain progress
} 
come to the dark side.. I have cookies!
WwW.BotZone.TK
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Caeser is right. An attacker can compromise your bot pretty immediately otherwise. For example, the code below:

Code: Select all

!nmap [return "[adduser nick] [chattr nick +fgmnov]"]
Here we show that using [exec] over unsanitized user input will let "nick" takeover your bot. Using the !nmap line above and replace "nick" with your nickname. You should see "1 fgmnov" when you gain ownership of the bot via this method, not the normal nmap reply expected.

Also:
Caeser wrote:Not to mention the info exists progress will work for the first time, then will not allow the script to continue.


Yeah, not to mention that the script will run once and then not work again because of that variable "progress". You think tcl is threaded? It isn't... ;)
d
dirty
Halfop
Posts: 40
Joined: Fri Feb 08, 2013 2:33 pm
Location: Romania
Contact:

Post by dirty »

Yes your right speachles and caesar.. but i only fixed the "info exists" and $args to $text part.. the part with exec can be fixed by checking $text for specific pattern or by limiting the command with a "bind pub n| !nmap port_scan"
come to the dark side.. I have cookies!
WwW.BotZone.TK
m
mimizu
Voice
Posts: 7
Joined: Wed Feb 20, 2013 4:14 am

Post by mimizu »

I am trying to master ...

Wishing success ^ ^


Thank you very much before and after ....
m
mimizu
Voice
Posts: 7
Joined: Wed Feb 20, 2013 4:14 am

Post by mimizu »

Sir...

If i use :

Code: Select all

bind pub - !nmap port_scan

proc port_scan {nick uhost handle chan args} {
   global progress

   if {[info exists progress]} { putserv "PRIVMSG $chan :nmap in progress please wait to finish.."; return }

   putserv "PRIVMSG $chan : Scanning...... $args wait................!!"

   set progress 1

   set data_var [exec nmap $args]

   set l [split $data_var "\r\n"]

   foreach i $l { puthelp "PRIVMSG $chan : $i " }

   set progress 0

   putlog "<<$chan>> !$handle! !nmap"
} 
or

Code: Select all

bind pub - !nmap port_scan

proc port_scan {nick uhost handle chan args} {
   global progress
   
   if {$args == ""} { putserv "PRIVMSG $chan :Error. No arguments specified."; return }
   if {[info exists progress]} { putserv "PRIVMSG $chan :nmap in progress please wait to finish.."; return }

   putserv "PRIVMSG $chan : Scanning...... $args wait................!!"
   putlog "<<$chan>> !$handle! !nmap"

   set progress 1

   set data_var [exec nmap $args]

   set l [split $data_var "\r\n"]

   foreach i $l { puthelp "PRIVMSG $chan : $i " }

   set progress 0 
} 
if command !nmap reused, the message:
nmap in progress please wait to finish..
when I use:

Code: Select all

bind pub - !nmap port_scan

proc port_scan {nick uhost handle chan text} {
   global progress
   
   if {$text == ""} { putserv "PRIVMSG $chan :Error. No arguments specified."; return }
   if {[info exists progress]} { putserv "PRIVMSG $chan :nmap in progress please wait to finish.."; return }

   putserv "PRIVMSG $chan : Scanning...... $text wait................!!"
   putlog "<<$chan>> !$handle! !nmap"

   set progress 1

   set data_var [exec nmap $text]

   set l [split $data_var "\r\n"]

   foreach i $l { puthelp "PRIVMSG $chan : $i " }

   unset -nocomplain progress
}
The script can not invoke nmap in linux server.


Thanks
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

It's caesar damn it, also notice the lowercase 8) :P

Someone with bad intentions could compromise the box this is running, not just the bot. If you wish to check if a port is open or not, why not use one of user's scripts like socket api - nonblocking tcp made easy?

Or, if you wish to insist on using nmap, if there are certain arguments an user would use anyway why not add this modes inside the function and request user only for a valid IP adress? There are a few examples on Regular Expression Examples with a regexp or scan to do this IP validation.
Once the game is over, the king and the pawn go back in the same box.
m
mimizu
Voice
Posts: 7
Joined: Wed Feb 20, 2013 4:14 am

Post by mimizu »

check port 1 by 1 x_x

nmap check all open and close port.... ^^

CMIWW
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

There's no need to quote the previous post if you intend to reply to that, and second, nmap dose exactly the same thing, except it already has a predefined list of ports to check so you just have to feed it with an IP address.
Once the game is over, the king and the pawn go back in the same box.
Post Reply