Thread: Functions

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    6
    Rep Power
    0

    Functions


    So trying to run the following code:

    Code:
    import socket
    def retBanner(ip, port):
    	try:
    		socket.setdefaulttimeout(2)
    		s = socket.socket()
    		s.connect((ip, port))
    		banner = s.rec(1024)
    		return banner
    	except:
    		return
    def checkVulns(banner):
    	if 'FreeFloat FTP Server (Version 1.00)' in banner:
    		print "[+] FreeFloat FTP Server is vulnerable."
    	elif '3Com 3CDaemon FTP Server Version 2.0' in banner:
    		print "[+] 3CDaemon FTP Serveer is vulnerable."
    	elif 'Ability Server 2.34' in banner:
    		print "[+] Ability FTP Server is vulnerable."
    	elif 'Sami FTP Server 2.0.2' in banner:
    		print "[+] Sami FTP Server is vulnerable."
    	else:
    		print "[-] FTP Server is not vulnerable."
    	return
    def main():
    	ip1 = '50.28.72.71'
    	ip2 = '50.28.72.72'
    	ip3 = '50.28.72.73'
    	port = 21
    	banner1 = retBanner(ip1, port)
    	if banner1:
    		print '[+] ' + ip1 + ': ' + banner1.strip('\n')
    	checkVulns(banner1)
    	if banner2:
    		print '[+] ' + ip2 + ': ' + banner2.strip('\n')
    	checkVulns(banner2)
    	if banner3:
    		print '[+] ' + ip3 + ': ' + banner2.strip('\n')
    	checkVulns(banner3)
    if __name__ == '__main__':
    	main()
    and i keep getting the following error messages:

    Traceback (most recent call last):
    File "functions2.py", line 39, in <module>
    main()
    File "functions2.py", line 31, in main
    checkVulns(banner1)
    File "functions2.py", line 12, in checkVulns
    if 'FreeFloat FTP Server (Version 1.00)' in banner:
    TypeError: argument of type 'NoneType' is not iterable

    Any idea why this is happening? When i run:

    Code:
    import socket
    def retBanner(ip, port):
    	try:
    		socket.setdefaulttimeout(2)
    		s = socket.socket()
    		s.connect((ip, port))
    		banner = s.recv(1024)
    		return banner
    	except:
    		return
    def main():
    	ip1 = '50.28.72.71'
    	ip2 = '50.28.72.72'
    	port = 21
    	banner1 = retBanner(ip1, port)
    	if banner1:
    		print '[+] ' + ip1 + ': ' + banner1
    	banner2 = retBanner(ip2, port)
    	if banner2:
    		print '[+] ' + ip2 + ': ' + banner2
    if __name__ == '__main__':
    	main()
    It runs and i get the output:

    [+] 50.28.72.71: 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
    220-You are user number 2 of 50 allowed.
    220-Local time is now 18:40. Server port: 21.
    220-This is a private system - No anonymous login
    220-IPv6 connections are also welcome on this server.
    220 You will be disconnected after 15 minutes of inactivity.

    [+] 50.28.72.72: 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
    220-You are user number 2 of 50 allowed.
    220-Local time is now 18:40. Server port: 21.
    220-This is a private system - No anonymous login
    220-IPv6 connections are also welcome on this server.
    220 You will be disconnected after 15 minutes of inactivity.

    Any help would be much appreciated, thanks.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,854
    Rep Power
    481

    A likely cause is identified.


    Your spelling's poor. That's bad for a programmer. See "Serveer"
    Code:
    		print "[+] 3CDaemon FTP Serveer is vulnerable."
    Following this idea, we observe that the retBanner functions differ. In the one that failed because it returned the non-iterable None probably because the "s" object hasn't got a "rec" attribute and there was no default iterable banner you've written "s.rec(1024)". The successful version of the function says "s.recv(1024)".

    Trap errors with care. try: except: blocks hide bugs.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    6
    Rep Power
    0
    Originally Posted by b49P23TIvg
    Your spelling's poor. That's bad for a programmer. See "Serveer"
    Code:
    		print "[+] 3CDaemon FTP Serveer is vulnerable."
    Following this idea, we observe that the retBanner functions differ. In the one that failed because it returned the non-iterable None probably because the "s" object hasn't got a "rec" attribute and there was no default iterable banner you've written "s.rec(1024)". The successful version of the function says "s.recv(1024)".

    Trap errors with care. try: except: blocks hide bugs.
    Thanks for your response, i wrote this up quickly before work didnt notice that i missed the v. It runs with no errors now, but gives off no output. any idea why?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2009
    Location
    Nebraska, USA
    Posts
    875
    Rep Power
    275
    shouldn't your main definition be more like this?

    python Code:
     
    def main():
    	ip1 = '50.28.72.71'
    	ip2 = '50.28.72.72'
    	ip3 = '50.28.72.73'
    	port = 21
    	banner1 = retBanner(ip1, port)
    	if banner1:
    		print '[+] ' + ip1 + ': ' + banner1.strip('\n')
            checkVulns(banner1)
        banner2 = retBanner(ip2, port)
    	if banner2:
    		print '[+] ' + ip2 + ': ' + banner2.strip('\n')
            checkVulns(banner2)
        banner3 = retBanner(ip3, port)
    	if banner3:
    		print '[+] ' + ip3 + ': ' + banner3.strip('\n')
            checkVulns(banner3)
  8. #5
  9. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,854
    Rep Power
    481
    print the intermediate values of your various banners.
    Remember, python treats None as False when used conditionally.
    [code]Code tags[/code] are essential for python code and Makefiles!
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    6
    Rep Power
    0
    Originally Posted by DonR
    shouldn't your main definition be more like this?

    python Code:
     
    def main():
    	ip1 = '50.28.72.71'
    	ip2 = '50.28.72.72'
    	ip3 = '50.28.72.73'
    	port = 21
    	banner1 = retBanner(ip1, port)
    	if banner1:
    		print '[+] ' + ip1 + ': ' + banner1.strip('\n')
            checkVulns(banner1)
        banner2 = retBanner(ip2, port)
    	if banner2:
    		print '[+] ' + ip2 + ': ' + banner2.strip('\n')
            checkVulns(banner2)
        banner3 = retBanner(ip3, port)
    	if banner3:
    		print '[+] ' + ip3 + ': ' + banner3.strip('\n')
            checkVulns(banner3)
    Yeah that does work but im trying to get it to iterate through the IP addresses so i don't have to type them in individually.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    6
    Rep Power
    0
    Originally Posted by b49P23TIvg
    print the intermediate values of your various banners.
    Remember, python treats None as False when used conditionally.
    Sorry im completely new to Python, how would i go about doing this?

IMN logo majestic logo threadwatch logo seochat tools logo