Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escaping special characters in cmd

Tags:

escaping

cmd

I have a Windows .bat script in which I try to run a command with password in parameter. The password I want to be able to use is ~!@#$%^&*()_+|-=\][{}';:"/.>?,<.

From what I've read here, I should escape ^&|\<> with ^. From what I assume, I should escape " with \".

This gives me something like that:

runme.exe /password:"~!@#$%^^^&*()_+^|-=^\][{}';:\"/.^>?,^<"

But it doesn't work - my target app responds with logon failure.

How should I escape all these characters to be able to hardcode the password in my batch (ignoring the security issues by now)?

like image 862
NOtherDev Avatar asked Apr 24 '12 10:04

NOtherDev


People also ask

How do I use special characters in cmd?

In Windows, you can type any character you want by holding down the ALT key, typing a sequence of numbers, then releasing the ALT key.

How do you escape special characters?

Escape CharactersUse the backslash character to escape a single character or symbol. Only the character immediately following the backslash is escaped. Note: If you use braces to escape an individual character within a word, the character is escaped, but the word is broken into three tokens.

How do I escape from command line?

No escaping is used with single quotes. Use a double backslash as the escape character for backslash.

How do I escape a character in a batch file?

batch-file Escaping special characters Escape using caret(^) Most special characters can be escaped using the caret( ^ ).


2 Answers

Double the quote in the password and make sure the complete password is enclosed in quotes as well:

runme.exe /password:"~!@#$%%^^^&*()_+^|-=\][{}';:""/.>?,<"
like image 185
Christian.K Avatar answered Sep 18 '22 08:09

Christian.K


Give this a try, but if runme.exe's argument parser requires quotes as string encapsulators for passwords, the it's not going to work. If you need to have a quote in your password, then runme.exe needs to provide a way to escape it!

runme.exe /password:~!@#$%%^^^&*()_+^|-=\][{}';:"/.>?,<
like image 29
jon Avatar answered Sep 20 '22 08:09

jon