How to pass inputs from a script to command line - perl

I am a new newbie to scripting, fuzzing, and buffer overflows. I understand the basic concepts behind them though.
I am looking for a way to pass input from a script (I am thinking perl) to a command line.
I am trying to create a fuzzer for a buffer overflow.
I have a basic C program that takes input from the command line
I need a script that I can pass patterns through to this external program on the command line.
Any help would be appreciated. Thank you.

You can create a file for the inputs, with 11 lines in it (last line is just an empty line to simulate enter key for the last command line input), and then redirect this file to the C program:
./c_program < file_with_10_inputs
You can save the above line as a wrapper script (e.g., auto_exec.sh) and in perl do:
system("sh auto_exec.sh");

I think you have to handle the stdin an stdout of the external process, so it's a good idea use a module like IO::Async, which helps you a lot.

Related

Prevent printing to command line in MATLAB

Before you answer, I'm not looking for the functionality of ; to suppress command line printing.
I have a set of scripts which are not mine and I do not have the ability to change. However, in my scripts I make a call to these other scripts through evalin('base', 'scriptName'). Unfortunately, these other scripts do a lot of unnecessary and ugly printing to the command window that I don't want to see. Without being able to edit these other scripts, I would like a way to suppress output to the command line for the time that these other scripts are executing.
One potential answer was to use evalc, but when I try evalc(evalin('base', 'scriptName')) MATLAB throws an error complaining that it cannot execute a script as a function. I'm hoping there's something like the ability to disable command window printing or else redirecting all output to some null file much like /dev/null in unix.
I think you just need to turn the argument in your evalc example into a string:
evalc('evalin(''base'', ''scriptName'')');
Have you tried this solution
here ?
echo off;
I don't know if it will fit your needs, but another solution can be to open a new session of Matlab, and use there only minimized -nodesktop form (-just the command window). You can run from there the annoying scripts, and work on the main session as usual.
The problem here is that the sessions can't be synchronized, so if you need to work with the results of the scripts all the time, it'll be a little bit complicated. Maybe you can save the result to disk, than call it from the main session...
But it mainly depends on your workflow with those scripts.

Writing to multiple lines in command prompt VBSCript

I am writing code in VB script.
The script will executing commands for programming, erasing, verfying hex code on microcontrollers in serial production.
The vbscript executes Commad line interface which is running similar like windows command prompt.
After Ppcli.exe is started from VBScript, some commands are sent to the com port. The commamds are shown below:
Get port, OpenPort , SetPowerVoltage 3.3, SetProtocol, EraseAll,Program, ...etc.
Everything works great, but here is the problem. I can send commands in sigle string (Open Port, Set Power, Erase... etc.) but this kind of sending has a big issue.
I can't read the response for the sigle command (OK or not OK) and I can't send the whole hex file at once, because programmer only supports programming, verifying line by line. This means I have to read line from file and send it to microcontroller 128 times.
I have to send 128 commands for write lines in sigle string which is really not the good solution.
I would like to write do while loop, but every time I close command prompt window, the ports is automaticly closed and the communication is lost :(
I would like to know if is it possible to write to command line in the way to send:
Open Port
Read if it is OK or not OK
Program line form hex file 1
Verify line 1
Program Line 2
Verify line 2
etc.
I really don't know what to do, since I am not able to communicate with the programmer in any other way than single string sending. But the string is then very long and there is no diagnostic if something goes wrong while programming:(
I was sure that CLI (command line interface) would be the best choice to program microcontrollers but now I am stuck, since I didn't know that it is only possible programming row by row and not the whole hex program at once :(
If you have any solution for me I would be glad.
Can I run Perl code from VBS? I also have working pearl example for programming devices?
Thank you,
Separate commands with & sign.

how to read texts on the terminal inside perl script

Is there any way to capture the texts on termianl screen inside a perl script. I know there are some functions like system,exec,backticks but the problem is that they execute commands FROM the script.For ex:- in terminal i write cd/ (or) ls,and after that i run my perl script which will read what was written on termianl screen(in this case, scipt will capture cd/ (or) ls-whichever was given to termianl). I came with one solution that by passing the commands which you wrote on termianl as a command line arguments to the script,but any other way???
Like this maybe:
history | perl -ne 'print $_'
As I understand it, in a situation where you've typed some stuff into a terminal like this:
[tai#littlerobot ~] echo "Hello"
Hello
[tai#littlerobot ~] perl myscript.pl
You want myscript.pl to be able to access the echo "Hello" part, and possibly also the Hello that was that command's output.
Perl does not provide such a feature. No programming language does or can provide such a feature because the process in which your script/program runs has no intrinsic knowledge about what happened in the same terminal before it was run. The only way it could access this text would be if it could ask the currently running terminal, which will have some record of this information (i.e. the scrollback buffer), even if it cannot distinguish between which characters in the text were typed by you, and which are output. However, I know of no terminal that exposes that information via any kind of public API.
So if you want myscript.pl to be able to access that echo "Hello", you'll need to pass it to your script. Piping history to your script (as shown by Mark Setchell in his answer) is one technique. history is a shell built-in, so it has as much knowledge as your shell has (which is not quite the same knowledge as your terminal has). In particular it can give you a list of what commands have been typed in this shell session. However, it cannot tell you about the output generated by those commands. And it cannot tell you about other shell sessions, so doing this in Perl is fairly useless:
my #history = `tcsh -c history`;
The last thing you could try (though it would be incredibly complicated to do) would be to ask the X server (or Windows if running on that operating system) for a screen shot and then attempt to locate which rectangle the current terminal is running in and perform OCR on it. This would be fraught with problems though, such as dealing with overlapping windows.
So, in summary, you cannot do this. It's nothing to do with Perl. You cannot do this in any programming language.

How do I restrict Perl debugger output to lines in my own script?

I'm running the debugger in noninteractive mode, with the output written to a file. I want to print out each line of my Perl script as it executes, but only lines in the script itself. I don't want to see the library code (File::Basename, Exporter::import, etc.) that the script calls. This seems like the sort of thing that should be easy to do, but the documentation for perldebug only discusses limiting the depth for dumping structures. Is what I want possible, and if so, how?
Note that I'm executing my program as follows:
PERLDB_OPTS="LineInfo=temp.txt NonStop=1 AutoTrace=1 frame=2" perl -dS myprog.pl arg0 arg1
By default, Devel::DumpTrace doesn't step into system modules, and you can exercise fine control over what modules the debugger will step into (it's not easy, but it's possible). Something like
DUMPTRACE_FH=temp.txt perl -d:DumpTrace=quiet myprog.pl
would be similar to what you're apparently trying to do.
Devel::DumpTrace also does a lot more processing on each line -- figuring out variable values and including them in the output -- so it may be overkill and run a lot slower than perl -dS ...
(Crikey, that's now two plugs for Devel::DumpTrace this week!)
Are you talking about not wanting to step through functions outside of your own program? For that, you want to use n instead of s.
From perldebug:
s [expr] Single step. Executes until the beginning of another
statement, descending into subroutine calls. If an
expression is supplied that includes function calls, it too
will be singleā€stepped.
n [expr] Next. Executes over subroutine calls, until the beginning
of the next statement. If an expression is supplied that
includes function calls, those functions will be executed
with stops before each statement.

Possible to use Powershell to type a command into a third-party command line program?

I have an old, third party, command line, proprietary program which I'm calling from PowerShell.
Once started, this program accepts commands typed in followed by enter (like any other program), but it's very basic. It doesn't have flags, doesn't accept piped in arguments, etc. You have to start the program, type your command, hit enter and parse the results.
Is there a way I can use PowerShell to type in a command and get the resulting output? Right now the best solution I have is to call SendKeys.Send in a background job, but I'm not sure this will work.
Is there a better way?
check out this to see if it would work for you: http://wasp.codeplex.com/
legacy programs are hard to tell, however. this works with standard windows programs.