Fixed bug with atexec that would cause it to not retrieve command output

Made atexec output more consistent
main
byt3bl33d3r 2015-11-19 18:59:11 -07:00
parent a7be3ea0a7
commit a9e0ee99ec
1 changed files with 9 additions and 14 deletions

View File

@ -26,6 +26,7 @@ from gevent import sleep
from impacket import version from impacket import version
from impacket.dcerpc.v5 import tsch, transport from impacket.dcerpc.v5 import tsch, transport
from impacket.dcerpc.v5.dtypes import NULL from impacket.dcerpc.v5.dtypes import NULL
from StringIO import StringIO
class TSCH_EXEC: class TSCH_EXEC:
@ -57,12 +58,12 @@ class TSCH_EXEC:
#import traceback #import traceback
#traceback.print_exc() #traceback.print_exc()
logging.error(e) logging.error(e)
if str(e).find('STATUS_OBJECT_NAME_NOT_FOUND') >=0:
logging.info('When STATUS_OBJECT_NAME_NOT_FOUND is received, try running again. It might work')
def doStuff(self, rpctransport): def doStuff(self, rpctransport):
def output_callback(data): def output_callback(data):
print_att(data.strip()) buf = StringIO(data.strip()).readlines()
for line in buf:
print_att(line.strip())
dce = rpctransport.get_dce_rpc() dce = rpctransport.get_dce_rpc()
@ -113,18 +114,18 @@ class TSCH_EXEC:
<Command>cmd.exe</Command> <Command>cmd.exe</Command>
""" """
if self.__noOutput is False: if self.__noOutput is False:
xml+= """ <Arguments>/C %s &gt; %%windir%%\\Temp\\%s 2&gt;&amp;1</Arguments> xml+= """ <Arguments>/C {} &gt; %windir%\\Temp\\{} 2&gt;&amp;1</Arguments>
</Exec> </Exec>
</Actions> </Actions>
</Task> </Task>
""" % (self.__command, tmpFileName) """.format(self.__command, tmpFileName)
else: else:
xml+= """ <Arguments>/C %s</Arguments> xml+= """ <Arguments>/C {}</Arguments>
</Exec> </Exec>
</Actions> </Actions>
</Task> </Task>
""" % (self.__command) """.format(self.__command)
logging.info("Task XML: {}".format(xml)) logging.info("Task XML: {}".format(xml))
taskCreated = False taskCreated = False
@ -160,7 +161,6 @@ class TSCH_EXEC:
if self.__noOutput is False: if self.__noOutput is False:
smbConnection = rpctransport.get_smb_connection() smbConnection = rpctransport.get_smb_connection()
waitOnce = True
while True: while True:
try: try:
logging.info('Attempting to read ADMIN$\\Temp\\%s' % tmpFileName) logging.info('Attempting to read ADMIN$\\Temp\\%s' % tmpFileName)
@ -170,12 +170,7 @@ class TSCH_EXEC:
if str(e).find('SHARING') > 0: if str(e).find('SHARING') > 0:
sleep(3) sleep(3)
elif str(e).find('STATUS_OBJECT_NAME_NOT_FOUND') >= 0: elif str(e).find('STATUS_OBJECT_NAME_NOT_FOUND') >= 0:
if waitOnce is True: sleep(3)
# We're giving it the chance to flush the file before giving up
sleep(3)
waitOnce = False
else:
raise
else: else:
raise raise
logging.debug('Deleting file ADMIN$\\Temp\\%s' % tmpFileName) logging.debug('Deleting file ADMIN$\\Temp\\%s' % tmpFileName)