Creating metadata with CMD? - cmd

In a security+ class we were shown how to inject exes and etc into a file using CMD line. The command was along the lines of:
CMD > Notepad.exe "file.exe:otherfile.exe"
In his explanation it added Notepad to file.exe by the name of otherfile.exe.
The problem with this is that he claims it is injecting a file directly into that file, but he showed us how the file size doesn't change but total NTFS file system size changes.
I believe he is talking about generic metadata and not changing the file in any way. Can someone please clarify or give me a reference to the command he is talking about or a good explanation?

Try this, it may answer a few of your questions:
md test
cd test
dir
echo this is my file>file.txt
dir
echo alternative data stream>file.txt:hidden
dir
dir /r
del file.txt
dir /r

Related

Update timestamp of a directory on Windows

There is more or less well-known command line way to update the modification time of a file on Windows (described at Update file or folder Date Modified, for example):
copy /b somePath\fileName+,, somePath\
According to my experience it does for a file, but does not for a directory (tested on WinXP - the command did not fail, but the directory modification time was not updated).
I tried to adjust it for a directory using such a trick that we can "point" to the directory using a special "NUL" filename on Windows. I tried two ways to do that, but they don't work as well:
copy /b somePath\fileName\NUL+,, somePath\filename\
copy /b somePath\fileName\NUL+,, somePath\
Could anyone explain me why it does not work or what I am doing wrong?
It doesn't make any changes to the directory because the filename nul is not stored in the directory. Since the directory is not changed, its modification time doesn't change. You can do this instead:
type nul > somePath\fileName\SomeFileThatDoesNotExist.tmp && del somePath\fileName\SomeFileThatDoesNotExist.tmp

Windows batch autoanswer XCOPY /i

I have created a batch file which uses FOR command to read a file of FROM Directory, FROM File, TO Directory, TO File as the parameters. (I am giving the files NEW names in the destination)
Everything works great until I add a new file to the mix.
In XCOPY /i option says it is a directory (which is NOT true). IF I don't use /i it wants to know if it is a file or a directory. It is ALWAYS a File. Is there a way I can autoreply or does someone have another suggestions.
echo f|xcopy [options] [files*]
A short investigation did not yield an easy command line parameter solution.
If I got you right, you are trying to copy a file from one directory to a new directory + give it a new name in the new directory. Copying to the new directory should work fine when you terminate target directory name with a tailing '\' (backslash) - this should result in a file with the same name in the target dir. Renaming this file to the new name will be straight forward. However, it's two commands instead of one...
In case this does not work for you: maybe you can illustrate your qn with a sample / snippet of the batch file?

How to use the list files in a given directory via batch file without showing the full path?

I have searched for this everywhere so I hope it has not already been asked, but I have a batch file where the user can write his / her own 'scripts' if you will. When the batch file is ran for the first time it will make a directory under %appdata%\Mellow\Mango\scripts and these scripts will simply be .txt files. Anyway...
I am trying to list the 'scripts' to the user by using dir /b /s *.txt and the output is C:\Users\Tate\AppData\Roaming\Mellow\Mango\scripts\template.txt
My question is, sorry if I got off-topic before, how to display only template.txt and not the full file path. I simply would like to list all .txt files contained in the scripts folder. Thanks in advanced!
Current Output:
C:\Users\Tate\AppData\Roaming\Mellow\Mango\scripts\template.txt
C:\Users\Tate\AppData\Roaming\Mellow\Mango\scripts\another_script.txt
Desired Output:
template.txt
another_script.txt
Simply remove the /s
dir /b *.txt
That should do it :)

Ghostscript: how to merge PDFs with wild card on Windows

I'm trying to merge all *.pdf in directory :
gswin64c -q -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=Total_Files.pdf -dBATCH *.pdf
This is perfectly work for me on Linux, but when I run it on Windows
I'm getting **Error: /undefinedfilename in *.pdf.**.
Please could some one help me with this.
(My problem was practically exactly the same). My solution (with the help of previous answers) answers the original question slightly better (an actual MS-DOS example is below)
del filename.lst
for %%s in (C:\somefolder\some?wildcards*.pdf) do ECHO %%s >> filename.lst
gswin64c.... #filename.lst
To explain;
'>>' means append in MS-DOS - so firstly we delete file filename.lst
I read (just now in some other place) that %%s in MS-DOS batch files works (instead of %s). Obviously - one day the filenames may contain spaces (as mine did already) so better be safe and quote the filenames. So the better batch file is;
del filename.lst
for %%s in (C:\somefolder\some?wildcards*.pdf) do ECHO "%%s" >> filename.lst
gswin64c.... #filename.lst
Right now I just used this for inputting many EPS files - but many PDF files work fine too; as in the above example - I actually tested it with both - my result is a PDF with many EPS files in it - and many pages from multiple PDF files in one PDF (as per the question).
There was a previous question on this topic, the answer is the same, Ghostscript does not allow wildcards in the input filename, you must specify each file you want to have as input.
Why does it work on Linux ? Because the shell you are using expands '*.ps' to a full list of files before passing the command line to Ghostscript.
To do this in Windows you will need to execute a shell script, pipe the filenames to a file, then supply the file as an argument to GS.
EG, something like
for %s in (*.ps) do ECHO %s >> filename.lst
gswin64c.... #filename.lst
As alternative to the for loop
dir /b /o:n *.ps > filename.lst
gets the job done (/b to get the files only, /o:n to sort by name).
To solve the sorting problem completely, you could rename the first 9 files to 01->09, or open the output file in notepad and handle these few cases manually. But if you will have more than 100 files, this could be bothersome.
Sorry to stir up this one year old thread, which helped me with my problem, but I thought using 'dir' is easier, more flexible and doesn't need you to delete the file list before starting.

.bat file - cd to a directory with a space in its name and also using a variable?

ive written a quick .bat file that reads in the name of a directory typed in by the user, i store that variable in a variable, and then i want to actually cd to that directory.
i've tested it out with simple directories like "C:," for instance, and that works. however, when i'm dealing with the user entering in something like "C:\Documents and Settings\Desktop," i can't do cd %directory%\sampleFolder.
i keep getting an error of "the system cannot find the path specified," even though i'm using the full name. anyone know how to overcome this?
How about:
cd "%directory%\sampleFolder"
set /p DIR="path:"
cd %DIR%
Works just fine.
#ECHO OFF
ECHO Enter Directory
SET/p directory=
CHDIR %directory%
Works for me (Windows 7) but should work for XP/Vista/etc

Resources