mirror of https://github.com/cowrie/cowrie.git
62 lines
1.8 KiB
Python
62 lines
1.8 KiB
Python
|
#!/usr/bin/env python
|
||
|
|
||
|
import os, pickle, sys, locale
|
||
|
from stat import *
|
||
|
|
||
|
def recurse(root, tree, count = 0):
|
||
|
A_NAME, A_TYPE, A_UID, A_GID, A_SIZE, A_MODE, \
|
||
|
A_CTIME, A_CONTENTS, A_TARGET = range(0, 9)
|
||
|
T_LINK, T_DIR, T_FILE, T_BLK, T_CHR, T_SOCK, T_FIFO = range(0, 7)
|
||
|
|
||
|
for name in os.listdir(root):
|
||
|
path = os.path.join(root, name)
|
||
|
if path in (
|
||
|
'/root/realfs.txt',
|
||
|
'/root/createfs.py',
|
||
|
'/root/.bash_history',
|
||
|
):
|
||
|
continue
|
||
|
|
||
|
if os.path.islink(path):
|
||
|
s = os.lstat(path)
|
||
|
else:
|
||
|
s = os.stat(path)
|
||
|
|
||
|
entry = [name, T_FILE, s.st_uid, s.st_gid, s.st_size, s.st_mode, \
|
||
|
int(s.st_ctime), [], None]
|
||
|
|
||
|
if S_ISLNK(s[ST_MODE]):
|
||
|
entry[A_TYPE] = T_LINK
|
||
|
entry[TARGET] = os.path.realpath(path)
|
||
|
elif S_ISDIR(s[ST_MODE]):
|
||
|
entry[A_TYPE] = T_DIR
|
||
|
if path not in ('/proc', '/sys'):
|
||
|
recurse(path, entry[A_CONTENTS])
|
||
|
elif S_ISREG(s[ST_MODE]):
|
||
|
entry[A_TYPE] = T_FILE
|
||
|
elif S_ISBLK(s[ST_MODE]):
|
||
|
entry[A_TYPE] = T_BLK
|
||
|
elif S_ISCHR(s[ST_MODE]):
|
||
|
entry[A_TYPE] = T_CHR
|
||
|
elif S_ISSOCK(s[ST_MODE]):
|
||
|
entry[A_TYPE] = T_SOCK
|
||
|
elif S_ISFIFO(s[ST_MODE]):
|
||
|
entry[A_TYPE] = T_FIFO
|
||
|
else:
|
||
|
sys.stderr.write('We should handle %s' % path)
|
||
|
sys.exit(1)
|
||
|
|
||
|
tree.append(entry)
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
A_NAME, A_TYPE, A_UID, A_GID, A_SIZE, A_MODE, \
|
||
|
A_CTIME, A_CONTENTS, A_TARGET = range(0, 9)
|
||
|
T_LINK, T_DIR, T_FILE, T_BLK, T_CHR, T_SOCK, T_FIFO = range(0, 7)
|
||
|
|
||
|
tree = ['/', T_DIR, 0, 0, 0, 0, 0, [], '']
|
||
|
recurse('.', tree[A_CONTENTS], tree[A_CONTENTS])
|
||
|
|
||
|
sys.stderr.write('Doing stuff\n')
|
||
|
|
||
|
print pickle.dumps(tree)
|