1

hey i wanted to know what this expression in batch stands for, im trying to do a uac bypass and i need to send keystrokes to the cmd window and i saw a post that uses a batch code with this expression and i dont know what is the function if someone could explain me ill be grateful!

heres the code from: Press Keyboard keys using a batch file

@if (@CodeSection == @Batch) @then


@echo off

rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"

rem Start the other program in the same Window
start "" /B cmd

%SendKeys% "echo off{ENTER}"

set /P "=Wait and send a command: " < NUL
ping -n 5 -w 1 127.0.0.1 > NUL
%SendKeys% "echo Hello, world!{ENTER}"

set /P "=Wait and send an Up Arrow key: [" < NUL
ping -n 5 -w 1 127.0.0.1 > NUL
%SendKeys% "{UP}"

set /P "=] Wait and send an Enter key:" < NUL
ping -n 5 -w 1 127.0.0.1 > NUL
%SendKeys% "{ENTER}"

%SendKeys% "exit{ENTER}"

goto :EOF


@end


// JScript section

var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
dieeguds
  • 11
  • 2
  • it's a type of hybrid batch-jscript. A batch file can be written in hybrid with [VBS](https://stackoverflow.com/q/9074476/995714), [jscript](https://stackoverflow.com/q/21392487/995714), [HTA](https://stackoverflow.com/q/47793813/995714) or even [ini](https://stackoverflow.com/a/48393614/995714) – phuclv Jan 28 '18 at 14:05
  • 1
    Nothing wrong with the post, but since it is your first, and you haven't done so yet, please take the [tour], read [Ask] and [MCVE]. – jwdonahue Jan 29 '18 at 01:00
  • The explanation appears in the same answer you linked, after "For a further explanation of this solution, see: [GnuWin32 openssl s_client conn to WebSphere MQ server not closing at EOF, hangs](https://stackoverflow.com/a/16868982/778560)". The explanation is also extended in the _comments_... – Aacini Jan 29 '18 at 18:50

1 Answers1

4

It isn't - it's Jscript.

If this file is run as Jscript, then since the if will fail, then the part between @then and @end will not be executed, and the Jscript part will be executed.

If it's run as a batch file, then since (@CodeSection is not equal to @Batch), the command @then will not be executed, hence the commands following that line will be executed, eventually reaching goto :eof which jums over the remainder of the file.

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • 1
    There should be a special hell for coders who don't explicitly state in a comment that this is their intent. I'd be willing to bet this kind of thing scores high on the list of things that waste noob to intermediate coder's time. Of course Microsoft is partly to blame for this crap. *nix systems standardized this sort of thing long ago. – jwdonahue Jan 29 '18 at 00:56