text
stringlengths
0
828
hasher = hashlib.new('md5', usedForSecurity=False)
with open(filename, 'rb') as afile:
buf = afile.read(blocksize)
while len(buf) > 0: # pylint: disable=len-as-condition
hasher.update(buf)
buf = afile.read(blocksize)
return hasher.hexdigest()
return ''"
4453,"def get_md5(string):
""""""Get a string's MD5""""""
try:
hasher = hashlib.md5()
except BaseException:
hasher = hashlib.new('md5', usedForSecurity=False)
hasher.update(string)
return hasher.hexdigest()"
4454,"def deploy_signature(source, dest, user=None, group=None):
""""""Deploy a signature fole""""""
move(source, dest)
os.chmod(dest, 0644)
if user and group:
try:
uid = pwd.getpwnam(user).pw_uid
gid = grp.getgrnam(group).gr_gid
os.chown(dest, uid, gid)
except (KeyError, OSError):
pass"
4455,"def get_local_version(sigdir, sig):
""""""Get the local version of a signature""""""
version = None
filename = os.path.join(sigdir, '%s.cvd' % sig)
if os.path.exists(filename):
cmd = ['sigtool', '-i', filename]
sigtool = Popen(cmd, stdout=PIPE, stderr=PIPE)
while True:
line = sigtool.stdout.readline()
if line and line.startswith('Version:'):
version = line.split()[1]
break
if not line:
break
sigtool.wait()
return version"
4456,"def verify_sigfile(sigdir, sig):
""""""Verify a signature file""""""
cmd = ['sigtool', '-i', '%s/%s.cvd' % (sigdir, sig)]
sigtool = Popen(cmd, stdout=PIPE, stderr=PIPE)
ret_val = sigtool.wait()
return ret_val == 0"
4457,"def check_download(obj, *args, **kwargs):
""""""Verify a download""""""
version = args[0]
workdir = args[1]
signame = args[2]
if version:
local_version = get_local_version(workdir, signame)
if not verify_sigfile(workdir, signame) or version != local_version:
error(""[-] \033[91mFailed to verify signature: %s from: %s\033[0m""
% (signame, obj.url))
raise ValueError('Failed to verify signature: %s' % signame)"
4458,"def download_sig(opts, sig, version=None):
""""""Download signature from hostname""""""
code = None
downloaded = False
useagent = 'ClamAV/0.101.1 (OS: linux-gnu, ARCH: x86_64, CPU: x86_64)'
manager = PoolManager(
headers=make_headers(user_agent=useagent),
cert_reqs='CERT_REQUIRED',
ca_certs=certifi.where(),
timeout=Timeout(connect=10.0, read=60.0)
)
if version:
path = '/%s.cvd' % sig
filename = os.path.join(opts.workdir, '%s.cvd' % sig)
else:
path = '/%s.cdiff' % sig
filename = os.path.join(opts.workdir, '%s.cdiff' % sig)
try:
req = manager.request('GET', 'http://%s%s' % (opts.hostname, path))
except BaseException as msg:
error(""Request error: %s"" % msg)
data = req.data
code = req.status
if req.status == 200:
with open(filename, 'w') as handle:
handle.write(data)
downloaded = os.path.exists(filename)
return downloaded, code"
4459,"def get_record(opts):
""""""Get record""""""
count = 1
for passno in range(1, 5):
count = passno
info(""[+] \033[92mQuerying TXT record:\033[0m %s pass: %s"" %
(opts.txtrecord, passno))
record = get_txt_record(opts.txtrecord)
if record:
info(""=> Query returned: %s"" % record)
break