forked from MozillaSecurity/peach
/
tftp.py
84 lines (71 loc) · 1.92 KB
/
tftp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os
import tftpy
from tftpy.TftpShared import TftpTimeout
import time
import socket
import struct
import sys
from Peach.publisher import Publisher
import Peach
class Tftp(Publisher):
"""
A simple TFTP client publisher.
"""
def __init__(self, host, port):
"""
@type host: string
@param host: Remote host
@type port: number
@param port: Remote port
"""
Publisher.__init__(self)
self.host = host
self.port = int(port)
self.withNode = True
self.client = tftpy.TftpClient(self.host, self.port)
def start(self):
pass
def stop(self):
pass
def connect(self):
"""
Create connection.
"""
pass
def close(self):
"""
Close connection if open.
"""
pass
#def send(self, data):
# """
# Send data via sendall.
# @type data: string
# @param data: Data to send
# """
# try:
# self.client.rawdata(data)
# except TftpTimeout:
# raise PublisherSoftException("failed: " + str(sys.exc_info()[1]))
def sendWithNode(self, data, dataNode):
'''
Publish some data
@type data: string
@param data: Data to publish
@type dataNode: DataElement
@param dataNode: Root of data model that produced data
'''
params = dict()
param_list = ["opcode", "filename", "mode"]
for child in dataNode.getAllChildDataElements():
if child.name in param_list:
if child.get_Value() is None:
params[child.name] = ""
else:
params[child.name] = child.get_Value()
try:
self.client.rawdata(params["opcode"], params["filename"], params["mode"])
except KeyboardInterrupt:
raise
except:
pass