파이썬 스크립트에는 2 개의 함수가 있습니다.Python3는 DB 쿼리 결과를 개별 문자열로 변환합니다.
첫 번째 것은 WHERE 절을 사용하여 데이터베이스에서 데이터를 가져 오지만 두 번째 함수는이 데이터를 사용하고 결과를 반복하여 파일을 다운로드합니다.
결과를 튜플로 인쇄 할 수 있습니까? 다운로드 기능의 URL에 그것을 추가 할 수 있도록
[('mmpc',), ('vmware',), ('centos',), ('redhat',), ('postgresql',), ('drupal',)]
는하지만 문자열로 각각의 요소를 통해 반복하는 데 필요한 response
변수 여기
import requests
import eventlet
import os
import sqlite3
# declare the global variable
active_vuln_type = None
# Get the active vulnerability sets
def GetActiveVulnSets() :
# make the variable global
global active_vuln_type
active_vuln_type = con = sqlite3.connect('data/vuln_sets.db')
cur = con.cursor()
cur.execute('''SELECT vulntype FROM vuln_sets WHERE active=1''')
active_vuln_type = cur.fetchall()
print(active_vuln_type)
return(active_vuln_type)
# return str(active_vuln_type)
def ExportList():
vulnlist = list(active_vuln_type)
activevulnlist = ""
for i in vulnlist:
activevulnlist = str(i)
basepath = os.path.dirname(__file__)
filepath = os.path.abspath(os.path.join(basepath, ".."))
response = requests.get('https://vulners.com/api/v3/archive/collection/?type=' + activevulnlist)
with open(filepath + '/vuln_files/' + activevulnlist + '.zip', 'wb') as f:
f.write(response.content)
f.close()
return activevulnlist + " - " + str(os.path.getsize(filepath + '/vuln_files/' + activevulnlist + '.zip'))
현재는 그래서 첫 번째에 대한 mmpc.zip 될 실제 파일이 아닌 ('mmpc',).zip
로 손상된 .ZIP을 생성하지만 그것은 단지 생성 중 하나로 목록을 반복하지 않는 것DB의 첫 번째 결과에 대한 zip 파일, 다른 것은 아니지만 print(i)
이 반환됩니다. [('mmpc',), ('vmware',), ('centos',), ('redhat',), ('postgresql',), ('drupal',)]
스크립트가 작동한다고 생각할 때 추적 코드가 없습니다.
'active_vuln_type = cur.fetchall()'을'active_vuln_type = [curl의 x에 대해 x [0] '과 (과) 같은 것으로 대체 하시겠습니까? – Abdou
나는 그 수준에서 두뇌 방귀 모멘트를 반복 할 생각을하지 못했다! 나는 그것에게 소용돌이를 줄 것이다! – Luke
그게 내게 첫 번째 결과를 올바르게 가져 오지만 iterating 및 결과의 나머지 부분을 얻고 있지 않다. – Luke