Join the fight to protect free speech on the internet and in general.

grey hat labs


G.H.L. Legal Disclaimer


Please note that I do participate in the Amazon llc affiliate program which means I earn money for promoting products listed on their site. When people click the ads and make purchases, I get paid a cut. Thank you! Pretty please allow the popups to load as they pay for this site! Pay it forward please, as I am offering you free software and tutorials that I work for!




This site is sponsored by Bounty Botanicals. Tell him Scott sent you.

If you're going to pursue computer science, please do something good with it.. If you want to become a programmer, or even pen tester, you should probably learn to write scripts and work with the command prompt ( aka terminal[used more in Unix/Linux terminology] ). It's a lot of fun but what you can do with Batch is limited. It's very powerful never the less, so don't let that fool you. It's the syntax that only goes so far. Understanding how to communicate with the Operating System via this command prompt essentially gives you the same powers as changing settings through the GUI(Control Panel).


Dos / Batch Commands

What is batch?

Batch is a pseudo-programming language that's integrated with the Microsoft windows operating system. It was built into MS-DOS back in the day. [date] It shares some similarities to MS-BASIC but has much less capability in many ways. It's used for system administration purposes, for fun, or recreation. It allows direct communication with the operating system. You can pretty much control any aspect of Windows from there. This is where security and user specific settings and restrictions come in, as well as secure passwords, antivirus, and firewall software. You really do have to TRY to have a secure system these days. Always update your operating system with system updates.


append, attrib, cd, copy, dir ,erase, find, mkdir, rmdir, where, for, type, echo, ping, del, rmdir, msg, net use, net view, net share, time, date, move, >, >>, fsutil, reg add, reg delete, reg query, sc start/stop, telnet, ftp,


You can also compile your batch scripts into full fledge executables. There are even some GUI syntax for your batch programs. Bash scripting similarly, allows even further GUI capabilities that most are un-aware of. [ Bash is the linux equivilant to batch ] Although powershell scripting is more of the modern Microsoft shell language, batch is still applicable and has evolved over the years as well. Thank you for using this website. Please contribute financially by buying from these great shops or making a donation via paypal to: stonedAimuser@Aim.com.



attrib

- Allows to hide or un-hide files, directories, and more.

Just assume your command prompt is there like..
C:\Windows\-\>.. and this is where you enter the syntax examples.

Hide Example:

attrib c:\target_dir\*.py +H

The example syntax above tells the operating systems to hide all the .py[*.py] [python scripts] in the directory, which in this case is called "target_dir".


Un-Hide Example:

attrib c:\a_folder\*.txt -H

In the example above, we tell the os via the syntax to un-hide all the .txt files [ text files ]. so the H, represents "hide". That's what it stands for. -h un-hide, +h make hidden. Straight forward right? It works on directories as well, and you can use it on single files rather than entire archieves[ without the *.ext ]


File & Directory Examples:

attrib password.dat +H
attrib password.dat -H
attrib c:\hidethisfolder +H
attrib c:\showmebish -H



cd



copy

I don't have to tell you what this command does as the title says it all. You have quite a few options. You can copy whole directories, or specific files in whole directories, and entire drive, or even add files into an image in a hidden way, which i'll show you in an article [ coming soon ].


copy a:\file.exe c:\windows\file.exe /y

Again, the /y tag tells the command prompt interpreter not to ask you if you're sure. It's good practice to not use it unless you're absolutely sure.





dir

dir /ad

List all directories only.

dir /b c:\windows # list only filenames in c:\windows

Leave out time stamps, file size, and other information.

dir /p pause per page

dir /w pause page page wide view

dir /w /p duh.

dir /q file.ext

Gives you detalied output on the file, even more information that's given by default, including the owner and pc the file belongs to.

dir *.py

dir *.exe

dir *s

dir /b *s

dir /b c:\folder *s







erase

erase filename.ext /f

/f tells the command prompt interpreter not to ask you if you're sure. Use with caution.

mkdir

mkdir stands for make directory.

rmdir c:\name-of-dir

Note: If you use spaces in your folder names, you'll need to use quotes to reference them. See the example below.

mkdir "c:\program files\software_name\file"



where

Where is used to find files. If you like this you may also want to try out:

dir /s /b c:\ | find /i "_searchString"

instead.

where /r c:\ *.rar

where /r c:\ python

where /r c:\mypics vacation

where /r c:\exif_data image2



for loops

For loops are really cool. They make your job a lot easier, and your code a lot less lame and a lot more cool. They are an integrated concept in all computer programming languages and computer science in general. Below are some awesome examples of using for loops in the command prompt or even in batch scripts. At times I've noticed, you may need to use %%A vs %A as you reference your variables because if memory serves batch and the actual console [ command prompt ] sometimes react to these differently, and require their one or the other. So, if one doesn't work, use the other. In different versions of DOS back in the day, [ Disk Operating System ], syntax did very slightly among different flavors.

In a nuttshell:

You can use for loops to iterate through files, and the output of commands. See the examples below.

for /f %A in ('net share') do ( net share %A /delete )

This will loop through each netbios share on your pc. These are shared resources made available across your file sharing network. They can pose a security risk. It's important to choose a password for your administrator that's secure. I suggest removing these unless you really need them. Using a firewall on top is also advised although they can be a bit rough to setup. They can often interfere with software causing manual action not suited for all computer users. It's definately geek territory to some. Even if you use secure password generators, it's a good idea to change a few characters. It's not that hard to do. I'm working on a new version of my secure password generator that gets user input to add an extra mile in the effort to obtain truely random numbers.

for loop in command prompt or batch through file

for /f %A in (file.ext) do ( echo %A )

This will echo all of the contents of said file one line at a time.

Let me break it down further.

Here is a console session where I dump 3 pieces of data to a file called test.dat. The data equals the strings, a, b, and c. Then we use a for loop to iterate through each one of them one line at a time. Sometimes quotation marks are needed when spaces are involved as a genereal rule of thumb in the terminal and batch.

Check back soon! Site under construction!

Grey Hat Laboratories
XML Sitemap  Contact: Webmaster@GreyHatLaboratories.com  Mobile Site

This Page Is Desktop Friendly Bish (#_#)
Because ----> # [ This "Mobile Revolution" Sucks ]