Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python3 D版生成config #364

Open
yurensmile opened this issue Nov 24, 2020 · 2 comments
Open

python3 D版生成config #364

yurensmile opened this issue Nov 24, 2020 · 2 comments

Comments

@yurensmile
Copy link

yurensmile commented Nov 24, 2020

# -*- coding: utf-8 -*-
"""
Created on Wed Dec 03 23:45:49 2014
Last Modified: 2016/10/19 12:13
@author: latyas
"""

from binascii import hexlify
import re, chardet

def hexed(s):
    ret = ''
    for i in s:
        ret += '\\x' + hex(ord(i))[2:].rjust(2, '0')
    return ret

filename = 'a.pcapng'
f = open(filename, 'r', encoding='ISO-8859-1')
text = f.read()

offset = re.search('\xF0\x00\xF0\x00[\x00-\xFF]{4}[\x03\x07]\x01', text).start() + 8
#print hexlify(text[offset:offset+330])
#print hexlify(text[offset:offset+338])
# print text[offset+334:offset+338].encode('hex')
if re.match('\x00\x00[\x00-\xFF]{2}', text[offset+334:offset+338]):
    ror_version = True
else :
    ror_version = False
# print ror_version
username_len = ord(text[offset+3]) - 20
username = text[offset+20:offset+20+username_len]
print('server = \'%s\'' % '.'.join([str(ord(i)) for i in text[offset-12:offset-8]]))
print('username=\'%s\'' % username)
print('password=\'\'')
print('CONTROLCHECKSTATUS = \'%s\'' % hexed(text[offset+56]))
print('ADAPTERNUM = \'%s\'' % hexed(text[offset+57]))
print('host_ip = \'%s\'' % '.'.join([str(ord(x)) for x in text[offset+81:offset+85]]))
print('IPDOG = \'%s\'' % hexed(text[offset+105]))
print('host_name = \'%s\'' % 'GILIGILIEYE')
print('PRIMARY_DNS = \'%s\'' % '.'.join([str(ord(x)) for x in text[offset+142:offset+146]]))
print('dhcp_server = \'%s\'' % '.'.join([str(ord(x)) for x in text[offset+146:offset+150]]))
print('AUTH_VERSION = \'%s\'' % hexed(text[offset+310:offset+312]))
if ror_version:
    print('mac = 0x%s' % hexlify(bytes(text[offset+328:offset+334], encoding='ISO-8859-1')))
else:
    print('mac = 0x%s' % hexlify(bytes(text[offset+320:offset+326], encoding='ISO-8859-1')))
print('host_os = \'%s\'' % 'NOTE7')

KEEP_ALIVE_VERSION = [i for i in re.findall('\xf0\x00\xf0\x00....\x07.\x5c\x28\x00\x0b\x01(..)', text) if i != '\x0f\x27'][0]
print('KEEP_ALIVE_VERSION = \'%s\'' % hexed(KEEP_ALIVE_VERSION))
print('ror_version = %s ' % ror_version)
@bnrh
Copy link

bnrh commented Feb 25, 2022

你好,非常感谢你的付出,我在使用该程序输出的config复制到M大发布的[latest-wired-python3.py]时仍有一些问题,经查找修正发现是python3的语法结构改变,我已将您的代码稍作修改贴在下面,输出内容可直接复制到[latest-wired-python3.py]中使用

@bnrh
Copy link

bnrh commented Feb 25, 2022

-- coding: utf-8 --

"""
Created on Wed Dec 03 23:45:49 2014
Last Modified: 2016/10/19 12:13
@author: latyas
"""

from binascii import hexlify
import re, chardet

def hexed(s):
ret = ''
for i in s:
ret += '\x' + hex(ord(i))[2:].rjust(2, '0')
return ret

filename = 'dr.pcapng'
f = open(filename, 'r', encoding='ISO-8859-1')
text = f.read()

offset = re.search('\xF0\x00\xF0\x00[\x00-\xFF]{4}[\x03\x07]\x01', text).start() + 8
if re.match('\x00\x00[\x00-\xFF]{2}', text[offset+334:offset+338]):
ror_version = True
else :
ror_version = False
username_len = ord(text[offset+3]) - 20
username = text[offset+20:offset+20+username_len]
print('server = '%s'' % '.'.join([str(ord(i)) for i in text[offset-12:offset-8]]))
print('username='%s'' % username)
print('password='请更改为你自己的密码'')
print('CONTROLCHECKSTATUS = b'%s'' % hexed(text[offset+56]))
print('ADAPTERNUM = b'%s'' % hexed(text[offset+57]))
print('host_ip = '%s'' % '.'.join([str(ord(x)) for x in text[offset+81:offset+85]]))
print('IPDOG = b'%s'' % hexed(text[offset+105]))
print('host_name = '%s'' % 'GILIGILIEYE')
print('PRIMARY_DNS = '%s'' % '.'.join([str(ord(x)) for x in text[offset+142:offset+146]]))
print('dhcp_server = '%s'' % '.'.join([str(ord(x)) for x in text[offset+146:offset+150]]))
print('AUTH_VERSION = b'%s'' % hexed(text[offset+310:offset+312]))
if ror_version:
print('mac = 0x%s' % str(hexlify(bytes(text[offset+328:offset+334], encoding='ISO-8859-1')))[2:-1])
else:
print('mac = 0x%s' % str(hexlify(bytes(text[offset+320:offset+326], encoding='ISO-8859-1')))[2:-1])
print('host_os = '%s'' % 'NOTE7')

KEEP_ALIVE_VERSION = [i for i in re.findall('\xf0\x00\xf0\x00....\x07.\x5c\x28\x00\x0b\x01(..)', text) if i != '\x0f\x27'][0]
print('KEEP_ALIVE_VERSION = b'%s'' % hexed(KEEP_ALIVE_VERSION))
print('ror_version = %s ' % ror_version)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants