浏览代码

v0.20.2, more characters allowed in .qr - no more shell exec

master
Zac Herd 7 年前
父节点
当前提交
22851a0962
共有 1 个文件被更改,包括 6 次插入22 次删除
  1. +6
    -22
      bot.py

+ 6
- 22
bot.py 查看文件

@@ -31,7 +31,7 @@ from secret import token, lfmkey, steamkey
# CONFIGURATION

# bot version
version = "v0.20.1"
version = "v0.20.2"

# text shown by .help command
helptext = """I am a Discord bot written in Python
@@ -357,7 +357,6 @@ def on_message(message):
response = steamdata(tmp)

elif message.content.startswith('.qr '):
# generate QR code - DANGEROUS, CHECK CAREFULLY HERE
tmp = message.content[4:]

# send typing signal to discord
@@ -371,26 +370,11 @@ def on_message(message):
else:
print('ERROR: Failed to send typing signal to discord after 5 attempts')

# make sure there are no nasty characters
msg = re.sub(r'[^a-zA-Z0-9_ -]', '', tmp, 0)

# echo message
cmd = 'echo "\'' + msg + '\'"'
args = shlex.split(cmd)
echo = subprocess.Popen(args, stdout=subprocess.PIPE)

# generate QR code
cmd = 'qrencode -t png -o -'
args = shlex.split(cmd)
qr = subprocess.Popen(args, stdin=echo.stdout, stdout=subprocess.PIPE)

# upload file with curl and get URL
cmd = 'curl -F upload=@- https://w1r3.net'
args = shlex.split(cmd)
out = subprocess.check_output(args, stdin=qr.stdout)

# run piped commands
echo.wait()
# generate qr code
qr = subprocess.Popen('qrencode -t png -o -'.split(), stdin=subprocess.PIPE, stdout=subprocess.PIPE)
qr.stdin.write(tmp.encode('utf-8'))
qr.stdin.close()
out = subprocess.check_output('curl -F upload=@- https://w1r3.net'.split(), stdin=qr.stdout)

# send response
response = out.decode('utf-8').strip()


正在加载...
取消
保存