How to modify a packet before it is sent to a printer? - packet

I am using old (3 years) label software automatically print barcodes on a production line to a Zebra printer. I just realized and confirmed with their IT that this software, for whatever reason when a print job is triggered, it sends a ^PR6 to the printer, setting the print speed to 6 (and overwriting the 2 I have set). No amount of tooling around with the printers settings or properties we changed were able to override this. IT also told me this product is at end of life and likely no one there will make a patch on it.
It seems like my only solution is to somehow catch this packet before it goes from the server to the printer and remove this ^PR6 from the beginning of the packet so that the print job uses the printers settings. Is there a way that I can do this?
This is all on a Windows Server 2012 system.

Newer printers have a command override command. Send the following command to the printer that you want to ignore the ^PR6:
! U1 setvar "device.command_override.add" "^PR"
More information can be found in the ZPL manual:
https://www.zebra.com/content/dam/zebra/manuals/printers/common/programming/zpl-zbi2-pm-en.pdf

Related

Having Powershell Autofill command line prompt

There is an old command line tool my company uses to deploy log files to various servers.... whoever wrote it made it very very repetitive.
There is a lot of prompting that happens and I want to automate this process. We have a long term goal of replacing this .exe file down the line but for now automation works for the short term..
Example
./logdeploy.exe
Enter the destination folder:
I would like the powershell script to just automatically enter the folder, since its literally the same folder. because this exe is going to ask for it at least 20 times throughout this process, so copy paste just gets anyoing.
Is this even possible to do?
If there really is no way around simulating interactive user input in order to automate your external program, a solution is possible under the following assumption:
Your external program reads interactive responses from stdin (the standard input stream).
While doing so is typical, it's conceivable that a given program's security-sensitive prompts such as for passwords deliberately accept input from the terminal only, as so to expressly prevent automating responses.
If the first assumption holds, the specific method that must be used to send the response strings via stdin depends on whether the external program clears the keyboard buffer before each prompt.
(a) If it does not, you can simply send all strings in a single operation.
(b) If it does, you need to insert delays between sending the individual strings, so as to ensure that input is only sent when the external program is actively prompting for input.
This approach is inherently brittle, because in the absence of being able to detect when the external program is read to read a prompt response, you have to guess how much time needs to elapse between sending responses - and that time may vary based on many runtime conditions.
It's best to use longer delays for better reliability, which, however, results in increased runtime overall.
Implementation of (a):
As zett42 and Mathias R. Jessen suggest, use the following to send strings C:\foo and somepass 20 times to your external program's stdin stream:
('C:\foo', 'somepass') * 20 | ./logdeploy.exe
Again, this assumes that ./logdeploy.exe buffers keyboard input it receives before it puts up the next prompt.
Implementation of (b):
Note: The following works in PowerShell (Core) 7+ only, because only there is command output being sent to an external program properly streamed (sent line by line, as it becomes available); unfortunately, Windows PowerShell collects all output first.
# PowerShell 7+ only
# Adjust the Start-Sleep intervals as needed.
1..20 | ForEach-Object {
Start-Sleep 1
'C:\foo'
Start-Sleep 2
'somepass'
} | ./logdeploy.exe

Progress 4gl printer not following inputted number of copies

We are using a new printer unit but it didn't follow the inputted number of copies. We tried to print it on our old printer and it was able to follow the number of copies. The number of copies worked in DocuCentre S2320 printer but not in HP LaserJet Pro P1102.
This is the code used for calling the report.The numCopy variable is used for the number of copies.
RUN _printrb(rptDir,"Summary Report","","O","","","D","?","","",numCopy,vPage[1],vPage[2],no,"",yes,yes,no,"").

What happens when powershell script encounters EOF while a quote is open?

Unicorn.py generates a string that looks like
powershell -flag1 -flag2 "something " obfuscation; powershell "more gibbrish
Interestingly, if this command is saved in a file filename.txt Windows executes it before opening the file in notepad.txt (by which time the file is empty).
Why is the file executed despite the extension?
What does the script do when it encounters EOF after odd number of quotation marks?
Edited:
Unicorn (https://github.com/trustedsec/unicorn) is a script that "enables privilege elevation and arbitrary code execution". If you know what it means. Of course I did NOT put the actual string, just the key features.
Purely out of IT security interest.
I think that if you read the manual in unicorn.py, at absolutely no time does it say that the script should be left in the txt file.
The PowerShell script is written inside the txt file and called the "payload" (very hacker like). What is left for you is always how to execute this code on the victim's computer.
The manual proposes Word code injection, simply executing the PowerShell in cmd (I quote "Next simply copy the powershell command to something you have the ability for remote command execution."), Excel Auto_Open attack, and so on.
If reading the manual is too much there is always a video. The only time the "hacker" uses a notepad like is on his linux operated system (how ironic)… I watched it because I love this Papa Roach music Last Resort...
For those who are concerned about IT security I recommend this article dosfuscation. This is really instructive about how you have to be extra careful when receiving mails, outside document,... and how humanity can waste so much time spying, deceiving, inventing new twisted strategies... Aren't we great !
Windows like any other system has many system flaw but opening notepad is not one of them. Unless your notepad has been replaced by a hacker using unicorn…
There is an even number of brackets in the obfuscated script. Did you mix up '' with "?
Empty txt file means that you've sent the attack.txt over network to a drive accessible by updated antivirus and antivirus quarantined/deleted file contents. Since you didn't know about this interaction with antivirus your environment is NOT secure. Which means you might have other malware from previous test lurking on your "clean" network.

Send Ctrl+Z to serial port via command line

I am trying to send the following to the COM1 serial port via command line using ECHO or similar (I've also tried downloading a small program called serialsend, but I am stuck with how to send the equivalent of CTRL+Z. This is to send a SMS message via a Siemens TC35 GAM module. I am able to do it via Hyperterminal as a test and it works fine, but I cannot figure out how to send the CTRL+Z at the end to confirm the ned of the message.
This is what I have:
AT
AT+CMGF=1
AT+CMSG="+xxxxxxxxxxx"
HELLO
Now, after Hello, which is the message I want to send, I have to send CTRL+Z. But cannot figure out how to do it, I have tried this:
AT
AT+CMGF=1
AT+CMSG="+xxxxxxxxxxx"
HELLO
\x1A
As I read somehwere that this would be the equivalent of doing it, but it hasnt worked.
Can anyone help me with this? I have found solutions, but they are not command line, which is what I need.
I have also tried using this format:
ECHO AT > COM1:
But as I don't know how to send CTRL+Z I don't know if it is working.
I wrote the free command line program SerialSend that you mentioned. Since this question was originally posted, I've added an extra feature that allows arbitrary byte values to be included (in hex format) in the text you're sending via the serial port. For example, to send Ctrl-Z (26 decimal, 0x1A hex), just use the following command:
SerialSend /hex "\x1a"
Port name/number, baudrate, etc can be configured with additional command line arguments. For example,
SerialSend /baudrate 9600 /devnum 2 /hex "\x1a"
For more details, see the SerialSend home page.
Hope that helps!
Ted
Use this:
port.Write(txt_msgbox.Text + char.ConvertFromUtf32(26));
It works :)
type this command Serial.println((char)26); in Arduino code ... one square box will appear on serial monitor. Copy that square and paste in Notepad++. It will be displayed as SUB with black background. wheneever you want to type cntrl+z, just copy this SUB and paste in serial monitor. It works.

Powershell - MS Exchange E-mail Autoresponder

We've currently got an issue where we're receiving a lot of bounced e-mails (from an auto generated e-mail) back from people where a specified e-mail address is not valid (failure notice). I need to identify certain messages in the mailbox and respond automatically to them - as a newbie to Powershell I'm struggling a bit! I think I understand how to check for the occurrence of a string but I don't know how to iterate through an inbox to look at/get a handle on each message in turn and I don't know how to extract the subject or body text in order to analyse the contents and perform a string comparison. I fear this should be easy - but I can't find anything on the web that might do the job - can anyone help?
So just to clarify what you're looking for.
Mailbox A receives a large number of failure notice/bounce messages.
You'ld like your powershell script to search Mailbox A for every instance where the Subject line (or message body) contains "String X" and if there is a match, take some action?
Also, what version of Exchange are you using? You need to be at least on 2007 to use Exchange Command Shell. You'll then want to look over the Command Shell commands that can be run.
Look at the Exchange Message Tracking Log, and Pipe the results from one command you run to the next. Think of it like this...
(Run a command) | (Run another command on the results of the first command) | (Run a last command on the results of the second).
You can view an example on my website at:
http://www.technoctopus.com/?p=223
While not exactly the same, it might get you moving in the right direction.