0
Proofpointには、書き換えられたURLをデコードする単純なPythonスクリプトがあります。これは私がそれがうまくいくと仮定していたので、彼らによって書かれ、出版されました。これはPython 2.7対3.x.xのものでしょうか?私はPycharmsで今すぐ実行しようとしています。Python 3.6.2 Proofpoint Decoder IndexError:リストインデックスが範囲外にある
エラー:
File "C:/Users/PP-Decoder.py", line 10, in main
rewrittenurl = sys.argv[1]
IndexError: list index out of range
Process finished with exit code 1
コード:
#!python
import sys
import re
import urllib.parse
import html.parser
def main():
rewrittenurl = sys.argv[1]
match = re.search(r'https://urldefense.proofpoint.com/(v[0-9])/', rewrittenurl)
if match:
if match.group(1) == 'v1':
decodev1(rewrittenurl)
elif match.group(1) == 'v2':
decodev2(rewrittenurl)
else:
print('Unrecognized version in: ', rewrittenurl)
else:
print('No valid URL found in input: ', rewrittenurl)
def decodev1(rewrittenurl):
match = re.search(r'u=(.+?)&k=', rewrittenurl)
if match:
urlencodedurl = match.group(1)
htmlencodedurl = urllib.parse.unquote(urlencodedurl)
url = html.parser.HTMLParser().unescape(htmlencodedurl)
print(url)
else:
print('Error parsing URL')
def decodev2(rewrittenurl):
match = re.search(r'u=(.+?)&[dc]=', rewrittenurl)
if match:
specialencodedurl = match.group(1)
trans = str.maketrans('-_', '%/')
urlencodedurl = specialencodedurl.translate(trans)
htmlencodedurl = urllib.parse.unquote(urlencodedurl)
url = html.parser.HTMLParser().unescape(htmlencodedurl)
print(url)
else:
print('Error parsing URL')
if __name__ == '__main__':
main()