TheZeal0t Posted August 9, 2019 Share Posted August 9, 2019 I've had two BashBunny payloads fail on me (USB_File_Exfiltration and SmartFileExtract_Exfiltration) when I ran them in the morning, after working on them for a full day trying to get them to work (the night before). Debugging the scripts on Windows, I found out that the date/time stamp formatting for the filename was causing the issue. The hour is left-padded with a space in the AM. I found the following hint for creating Windows Batch Script variables that are properly formatted with the date/time. My modified code to match the format in the payload scripts is below: @echo off for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a" set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%" set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%" set "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%" & set "fullstamp=%YYYY%%MM%%DD%_%HH%%Min%%Sec%" echo datestamp: "%datestamp%" echo timestamp: "%timestamp%" echo fullstamp: "%fullstamp%" pause Here is the output: datestamp: "20190809" timestamp: "084546" fullstamp: "20190809_084546" Press any key to continue . . . And here is the link that helped me figure it out: How do I get current datetime on the Windows command line, in a suitable format for using in a filename? I hope this helps someone avoid the struggle I've been having the last two days. Link to comment Share on other sites More sharing options...
TheZeal0t Posted August 9, 2019 Author Share Posted August 9, 2019 Perhaps a simpler way is to just substitute 0's for spaces in the date/time stamp, like so: set dt=%DATE:~6,4%_%DATE:~3,2%_%DATE:~0,2%__%TIME:~0,2%_%TIME:~3,2%_%TIME:~6,2% set dt=%dt: =0% Format date and time in a Windows batch script Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.