本文整理汇总了Python中utility.CtfUtil.getRandomString方法的典型用法代码示例。如果您正苦于以下问题:Python CtfUtil.getRandomString方法的具体用法?Python CtfUtil.getRandomString怎么用?Python CtfUtil.getRandomString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utility.CtfUtil
的用法示例。
在下文中一共展示了CtfUtil.getRandomString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createUser
# 需要导入模块: from utility import CtfUtil [as 别名]
# 或者: from utility.CtfUtil import getRandomString [as 别名]
def createUser(mainpage,flag):
try:
userPage = mainpage.click("cgi-bin/createuser.php")
userPage.parse()
userForm = userPage.forms[0];
userName = CtfUtil.getRandomString(random.randint(6,8))
firstName = CtfUtil.getRandomString(random.randint(6,8))
lastName = CtfUtil.getRandomString(random.randint(6,8))
password = CtfUtil.getRandomAlphaNum(8)
email = flag
userForm.fields['username'] = userName
userForm.fields['lastname'] = lastName
userForm.fields['firstname']= firstName
userForm.fields['password'] = password
userForm.fields['email'] = email
resultPage = userForm.click(None)
successPtr = resultPage.page.find("User successfully created!")
if successPtr != -1:
return userName,password
else:
sys.exit(-1)
except Exception, e:
print "ERROR: got exception %s creating user" % (e)
sys.exit(-1)
示例2: score
# 需要导入模块: from utility import CtfUtil [as 别名]
# 或者: from utility.CtfUtil import getRandomString [as 别名]
def score(ip,flag,cookie):
#get old flag
if cookie != None:
try:
name = cookie
personality = browserpersonality.getRandomPersonality()
mainpg = pybrowse.Browser("http://" + ip + "/~feedback/cgi-bin/candidates.php", personality)
mainpg.open()
mainpg.parse()
candidate = random.randint(0,4)
feedbackForm = mainpg.forms[candidate]
feedbackForm.fields['name'] = name
feedbackForm.fields['comment'] = CtfUtil.getRandomString(5) + " " + CtfUtil.getRandomString(random.randint(4,9)) + random.choice(['?','.','!'])
resultPage = feedbackForm.click(None)
successPtr = resultPage.page.find("About")
if successPtr != -1:
oldFlag = resultPage.page[successPtr+9:][:len(flag)]
print "FLAG:",oldFlag
except Exception, e:
print "ERROR: got exception %s getting flag" % (e)
示例3: score
# 需要导入模块: from utility import CtfUtil [as 别名]
# 或者: from utility.CtfUtil import getRandomString [as 别名]
def score(ip,flag,cookie):
try:
#Login to ftp
ftp = ftplib.FTP(ip)
ftp.login()
ftp.cwd("/home/ftp/incoming")
if cookie != None:
ftp.retrlines("RETR "+cookie,flagCallback)
#set new flag
filename = CtfUtil.getRandomString(9)
file = open(filename,'w')
file.write(flag)
file.close();
file = open(filename,'r')
ftp.storlines("stor "+filename,file)
file.close()
os.remove(filename)
cookie = filename
print "COOKIE:",cookie
except Exception, e:
print "ERROR: Failed to set new flag!"
示例4: createAccount
# 需要导入模块: from utility import CtfUtil [as 别名]
# 或者: from utility.CtfUtil import getRandomString [as 别名]
def createAccount(name, passwd, role):
global myHost
mainpg = pybrowse.Browser("http://" + myHost + "/Therapy/createuser.do?role=" + role)
mainpg.open()
mainpg.parse()
userform = mainpg.forms[0]
userform.fields['firstname'] = CtfUtil.getRandomString(random.randint(4,10))
userform.fields['lastname'] = CtfUtil.getRandomString(random.randint(5,10))
userform.fields['email'] = CtfUtil.getRandomEmail()
userform.fields['username'] = name
userform.fields['password'] = passwd
userform.fields['role'] = role
resultPage = userform.click("submit")
resultPage = resultPage.doRedirects()
return resultPage
示例5: score
# 需要导入模块: from utility import CtfUtil [as 别名]
# 或者: from utility.CtfUtil import getRandomString [as 别名]
def score(ip,flag,cookie):
#get old flag
if cookie != None:
try:
wwid = cookie
vote = CtfUtil.getRandomString(random.randint(5,10))
response = sendMessage(ip,encrypt("!"+wwid+" "+vote))
successPtr = response.find("OK")
if successPtr != -1:
oldFlag = decrypt(response[successPtr+3:].strip())
print "FLAG:",oldFlag
except Exception, e:
print "ERROR: got exception %s getting flag" % (e)
示例6: score
# 需要导入模块: from utility import CtfUtil [as 别名]
# 或者: from utility.CtfUtil import getRandomString [as 别名]
def score(ip,flag,cookie):
#get old flag
if cookie != None:
try:
user,email = cookie.split(":")
resultPage = getNotePage(ip,user,email,CtfUtil.getRandomString(random.randint(5,10)))
successPtr = resultPage.page.find("NOTE:")
if successPtr != -1:
endPointer = resultPage.page[successPtr+6:].find("\n")
oldFlagText = resultPage.page[successPtr+6:][:endPointer]
oldFlag = urllib.unquote(oldFlagText)[:len(flag)]
print "FLAG:",oldFlag
except Exception, e:
print "ERROR: got exception %s setting new flag" % (e)
sys.exit(1)
示例7: create_flag
# 需要导入模块: from utility import CtfUtil [as 别名]
# 或者: from utility.CtfUtil import getRandomString [as 别名]
def create_flag(s, flag):
username = CtfUtil.getRandomString(6)
password = random.choice(good_password)
s.send('new %s %s\n'%(username,password))
res = readline(s)
if res[:3] != "200":
return ""
s.send("to: xxxx\n")
res = readline(s)
s.send("spam\n")
res = readline(s)
res = readline(s)
res = readline(s)
s.send("%s\n"%flag)
s.send(".\n")
res = readline(s)
return username+":"+password
示例8: str
# 需要导入模块: from utility import CtfUtil [as 别名]
# 或者: from utility.CtfUtil import getRandomString [as 别名]
except Exception, e:
print "ERROR: got exception %s getting flag" % (e)
#set the new flag
try:
personality = browserpersonality.getRandomPersonality()
mainpg = pybrowse.Browser("http://" + ip + "/~register/register.html", personality)
mainpg.open()
mainpg.parse()
registrationForm = mainpg.forms[0]
password = CtfUtil.getRandomAlphaNum(8)
wwid = flag
registrationForm.fields['first'] = CtfUtil.getRandomString(random.randint(5,7))
registrationForm.fields['last'] = CtfUtil.getRandomString(random.randint(6,9))
registrationForm.fields['dob'] = str(random.choice(months))+" "+str(random.randint(1,29))+", "+str(random.randint(1900,2000))
registrationForm.fields['email'] = CtfUtil.getRandomEmail()
registrationForm.fields['password'] = password
registrationForm.fields['wwid'] = wwid
resultingPage = registrationForm.click(None)
successPtr = resultingPage.page.find("Registration successful!")
if successPtr == -1:
print "ERROR: Could not set new flag"
return
cookie = password+":"+wwid
示例9: getRandomSentence
# 需要导入模块: from utility import CtfUtil [as 别名]
# 或者: from utility.CtfUtil import getRandomString [as 别名]
def getRandomSentence(len):
ret = ""
for i in range(len):
ret += CtfUtil.getRandomString(random.randint(1,8)) + " "
return ret
示例10:
# 需要导入模块: from utility import CtfUtil [as 别名]
# 或者: from utility.CtfUtil import getRandomString [as 别名]
print "ERROR: got exception [%s] getting flag" % (e)
sys.exit(1)
# set the new flag
try:
personality = browserpersonality.getRandomPersonality()
mainpg = pybrowse.Browser("http://" + ip + "/Site/Sound_of_music.html")
mainpg.open()
mainpg = pybrowse.Browser("http://" + ip + "/Site/Sound_of_music_files/widget1_markup.html")
mainpg.open()
mainpg.parse()
qForm = mainpg.forms[0]
myfirst =flag
mylast = CtfUtil.getRandomString(random.randint(3,10))
myemail = CtfUtil.getRandomEmail()
mypassword = CtfUtil.getRandomString(random.randint(3,10))
qForm.fields["first"] = myfirst
qForm.fields["last"] = mylast
qForm.fields["email"] = myemail
qForm.fields["password"] = mypassword
cookie = qForm.fields["email"] + ":" + qForm.fields["password"]
resultingPage = qForm.click(None)
resultingPage = resultingPage.doRedirects()
successPtr = resultingPage.page.find("successfully created")
if successPtr == -1:
print "ERROR: Error setting new flag"
示例11:
# 需要导入模块: from utility import CtfUtil [as 别名]
# 或者: from utility.CtfUtil import getRandomString [as 别名]
getFlagUrl = ip+"/~museum/cgi-bin/museum_admin.pl?first="+first+"&last="+last+"&password=unbreakable"
getFlagPage = pybrowse.Browser("http://" + getFlagUrl)
getFlagPage.open()
rawPage = getFlagPage.page
oldFlag = rawPage[253:][:len(flag)]
print "FLAG:",oldFlag
except Exception, e:
print "ERROR: got exception '%s' when getting flag" % (e)
return
#set new flag
try:
first = CtfUtil.getRandomString(random.randint(6,8))
last = CtfUtil.getRandomString(random.randint(6,8))
idea = urllib.quote(flag)
setFlagUrl = ip+"/~museum/cgi-bin/museum_upload.pl?first="+first+"&last="+last+"&dob=&ssn=&mmn=&email=&idea="+idea
mainpg = pybrowse.Browser("http://" + setFlagUrl)
mainpg.open()
resultPage = mainpg.page
successPattern = "Your idea has been received!!"
successPtr = resultPage.find(successPattern)
if successPtr >= 0:
cookie = first+":"+last
print "COOKIE:",cookie
示例12: score
# 需要导入模块: from utility import CtfUtil [as 别名]
# 或者: from utility.CtfUtil import getRandomString [as 别名]
def score(ip,flag,cookie):
try:
# -------------------------
# Retrieve old flag
# -------------------------
old_flag = "None"
real_path = execution_path("./snitch_data/snitch_clean.jpg")
save_path = execution_path("./snitch_data/%s.jpg"%ip)
font_path = execution_path("./snitch_data/arial.ttf")
if cookie:
name = cookie.replace("_"," ")
img = Image.open(real_path)
draw = ImageDraw.Draw(img)
font = ImageFont.truetype(font_path, 20)
draw.text(( 5, 40), name, fill="black", font=font)
draw.text(( 5, 80), "abcde", fill="black", font=font)
img.save(save_path)
f = open(save_path)
fdata = f.read()
f.close()
#print "Getting the flag..."
status, reason, data = post_multipart(
ip, "/~snitch/cgi-bin/snitch.py", [], [('paper',"%s"%save_path, fdata)])
pos = data.find("thanks to paper")
if pos != -1:
old_flag = data[pos+21:][:len(flag)]
print "FLAG:",old_flag
# -------------------------
# Set the new one
# -------------------------
img = Image.open(real_path)
draw = ImageDraw.Draw(img)
first = CtfUtil.getRandomString(random.randint(6,10))
last = CtfUtil.getRandomString(random.randint(6,10))
name = first + " " + last
address = "xxxxx"
#print "Generating picture..."
font = ImageFont.truetype(font_path, 20)
draw.text(( 5, 40), name, fill="black", font=font)
draw.text(( 5, 80), address, fill="black", font=font)
img.save(save_path)
#print "Setting exif info..."
os.popen("""exiv2 -M"set Exif.Photo.UserComment Paper_ID=%s" %s"""%(flag, save_path))
f = open(save_path)
fdata = f.read()
f.close()
#print "Setting flag..."
status, reason, data = post_multipart(
ip, "/~snitch/cgi-bin/snitch.py", [], [('paper', "%s"%save_path, fdata)])
#print "Status ",status
cookie = name.replace(" ","_")
print "COOKIE:",cookie
except Exception, e:
print "ERROR: %s" % e
示例13:
# 需要导入模块: from utility import CtfUtil [as 别名]
# 或者: from utility.CtfUtil import getRandomString [as 别名]
try:
personality = browserpersonality.getRandomPersonality()
# 1. go to the shell's page
mainpg = pybrowse.Browser("http://" + ip + "/Site/Bosses_and_artists.html")
mainpg.open()
# 2. create a new boss
mainpg = pybrowse.Browser("http://" + ip + ":" + myPort + "/bosses/new/")
mainpg.open()
mainpg.parse()
myform = mainpg.forms[0]
boss_name = CtfUtil.getRandomString(random.randint(6,16))
boss_pwd = CtfUtil.getRandomString(random.randint(6,8))
myform.fields["name"] = boss_name.capitalize()
myform.fields["username"] = boss_name
myform.fields["password"] = boss_pwd
myform.fields["password_again"] = boss_pwd
resultingPage = myform.click( None )
resultingPage = resultingPage.doRedirects( )
resultingPage.parse()
checkError(resultingPage)
# resulting page should be /bosses/view/N/
boss_id = resultingPage.documentroot.split("/")[3]
示例14:
# 需要导入模块: from utility import CtfUtil [as 别名]
# 或者: from utility.CtfUtil import getRandomString [as 别名]
personality = browserpersonality.getRandomPersonality()
mainpg = pybrowse.Browser("http://" + ip + "/Site/Would_you.html")
mainpg.open()
mainpg = pybrowse.Browser("http://" + ip + "/Site//Would_you_files/widget1_markup.html")
mainpg.open()
mainpg.parse()
qForm = mainpg.forms[0]
qForm.fields["q1"] = random.choice(("yes", "no"))
qForm.fields["q2"] = random.choice(("yes", "no"))
qForm.fields["q3"] = random.choice(("yes", "no"))
qForm.fields["q5"] = random.choice(("yes", "no"))
qForm.fields["q6"] = random.choice(("yes", "no"))
qForm.fields["q7"] = random.choice(("yes", "no"))
cookie = CtfUtil.getRandomString(random.randint(3,10))
qForm.fields["steal"] = flag
qForm.fields["signature"] = cookie
resultingPage = qForm.click(None)
resultingPage = resultingPage.doRedirects()
successPtr = resultingPage.page.find("was successfully saved.")
if successPtr == -1:
print "ERROR: cannot set flag"
print "COOKIE:",cookie
except Exception, e:
print "ERROR: got exception %s getting flag" % (e)
示例15:
# 需要导入模块: from utility import CtfUtil [as 别名]
# 或者: from utility.CtfUtil import getRandomString [as 别名]
print "FLAG:",oldFlag
except Exception, e:
print "ERROR: got exception %s getting flag" % (e)
# set the new flag
try:
personality = browserpersonality.getRandomPersonality()
mainpg = pybrowse.Browser("http://" + ip + "/Site/Petition.html")
mainpg.open()
mainpg = pybrowse.Browser("http://" + ip + "/Site//Petition_files/widget1_markup.html")
mainpg.open()
mainpg.parse()
myform = mainpg.forms[0]
myform.fields["first"] = CtfUtil.getRandomString(random.randint(4,10))
myform.fields["last"] = CtfUtil.getRandomString(random.randint(4,10))
myform.fields["email"] = CtfUtil.getRandomEmail()
myform.fields["comment"] = flag
myform.fields["id"] = ""
resultingPage = myform.click(None)
resultingPage = resultingPage.doRedirects()
successPtr = resultingPage.page.find( "Your ID is " )
if successPtr != -1:
cookie = resultingPage.page[successPtr+11:][:8]
print "COOKIE:",cookie
except Exception, e:
print "ERROR: got exception %s setting new flag" % (e)