rem overflow

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

rem overflow

#1 Post by npocmaka_ » 16 Oct 2015 00:09

Example (I dont know why But I couldnt put the code here).


the commented line must contain 8198 characters and at least one of them delimited.Then you can add & and some command.

Tested on Win8.1 x 64

The only potential 'usage' I see is for malicious scripts where nobody will expect the last part to be executed.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: rem overflow

#2 Post by penpen » 16 Oct 2015 04:50

Strange:
If i replace the space between the '1' and '2' with a 'z' it doesn't echo.


penpen

mcnd
Posts: 27
Joined: 08 Jan 2014 07:29

Re: rem overflow

#3 Post by mcnd » 16 Oct 2015 11:49

Not the first time it bites. Do you think this is related?

More than a rem overflow I think it is a parser buffer overflow. What I see it that the parser will remove the starting rem and the initial delimiter (the first space) so the ampersand falls in the position 8192, the buffer is splitted at this point and the @echo is executed in the next buffer instance

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: rem overflow

#4 Post by npocmaka_ » 16 Oct 2015 12:32

penpen wrote:Strange:
If i replace the space between the '1' and '2' with a 'z' it doesn't echo.


penpen


Exactly . There should be at list one delimiter in the remarked line.


Not the first time it bites. Do you think this is related?

More than a rem overflow I think it is a parser buffer overflow. What I see it that the parser will remove the starting rem and the initial delimiter (the first space) so the ampersand falls in the position 8192, the buffer is splitted at this point and the @echo is executed in the next buffer instance


The behavior with the spaces looks very similar.Probably yes....

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: rem overflow

#5 Post by jeb » 17 Oct 2015 09:36

Nice experiment :D :!:

I suppose it's caused by the special REM parser, as the rem parser examines the first token (after the rem) to check if it's /? and the next token will be ignored completely.

Sample

Code: Select all

@echo ON
REM Hello^
This line is part of the comment

REM Hello world^
This Line is NOT a comment


But in your case, the REM and the ECHO are executed.

Code: Select all

@echo off
rem /? 7890zz....zzz&ECHO Works

I used 8180 z's here

Output wrote:Leitet Kommentare in einer Batchdatei oder in CONFIG.SYS ein.

REM [Kommentar]
Works


I tried it with labels(:) but can't find any similar behaviour :(

Post Reply