Dark Developments Where Knowledge Meets Power

12Jun/120

BATCH – Check Network Connection

Posted by Dark#Basics

BATCH - Check Network Connection

A couple of days ago we've installed a ThinClient at one of our customers. The point of the TC is to start a web browser in FullScreen mode and preform as an information screen. The website itself refreshes at a certain time displaying new information. The problem was that the network connection was done wireless and thus when the client is booted we'll need to check the network connection before running the browser. The following BATCH script did the trick.

Select All Code:
1
2
3
4
5
6
7
8
@echo off
set ip=8.8.8.8
 
:check_loop
ping -n 1 %ip%
if %ERRORLEVEL% NEQ 0 goto check_loop
 
START [PATH TO CHROME-LNK]
Filed under: Batch, Programming No Comments
9Aug/110

PY – Hashing

Posted by Dark#Basics

Basic Python code that displays how to:
- Use import
- Use classes and function calls
- Read arguments
- Handle exeptions
- Handle encodings

Select All Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
@author: Dark#Basics @email: darkbasics@darkdevelopments.org @website: darkdevelopments.org
 
''' This module implements a common interface to many different secure hash and message digest algorithms. Included are the FIPS secure hash algorithms SHA1, SHA224, SHA256, SHA384, and SHA512 (defined in FIPS 180-2) as well as RSA’s MD5 algorithm. The terms secure hash and message digest are interchangeable. Older algorithms were called message digests. The modern term is secure hash. '''
import hashlib;
''' This module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. '''
import sys;
''' This module helps scripts to parse the command line arguments in sys.argv. It supports the same conventions as the Unix getopt() function (including the special meanings of arguments of the form ‘-‘ and ‘--‘). Long options similar to those supported by GNU software may be used as well via an optional third argument. '''
import getopt;
 
''' Contains all the functionality for the script '''
class Hashing:
 
    #Help for this class def _help_(self):
        print( '\n===============================================================')
        print( '\hashing.py -p [plaintext]')
        print( '-p [plaintext] Plaintext to encrypt')
        print( '-h Show help')
        print( '===============================================================')
 
    # Hash plaintext argument to MD5 equivalent. Do note when using the md5 function that the string needs to be in unicode. # Putting a String-object to unicode/UTF8 can be done by using the encode-function. # Hexdigest returns a string of double length, containing only hexadecimal digits. This may be used to exchange the value safely in email or other non-binary environments. def _hashit_(self,plaintext):
        print('\n[+] Plaintext: '+ plaintext + ' \n[+] MD5-hash: ' + hashlib.md5(plaintext.encode('utf8')).hexdigest())
 
#Process starts here if __name__ == '__main__':
 
    #Print a header print(' ____ __ ____ __ __ ')
    print(' / __ \____ ______/ /__/ __ \___ _ _____ / /____ ____ ____ ___ ___ ____ / /______')
    print(' / / / / __ `/ ___/ //_/ / / / _ \ | / / _ \/ // __ \/ __ \/ __ `__ \/ _ \/ __ \/ __/ ___/')
    print(' / /_/ / /_/ / / / ,< / /_/ / __/ |/ / __/ // /_/ / /_/ / / / / / / __/ / / / /_(__ ) ')
    print('_____/\__,_/_/ /_/|_/_____/\___/|___/\___/_/ \____/ .___/_/ /_/ /_/\___/_/ /_/\__/____/ ')
    print(' /_/ ')
    print('Tool:Hashing Tool\nAuthor:Dark#Basics\nWebsite:darkdevelopments.org')
 
    #Create object h = Hashing()
 
    #Try and read the arguments try:
        #Read arguments with getopt opts, args = getopt.getopt(sys.argv[1:], 'p:h')
        for o, arg in opts:
            if o == '-p' and isinstance(arg,str):
                h._hashit_(arg)
            elif o == '-h':
                h._help_()
            else:
                raise Exception()
 
    #If all fails except:
        print("\n[+] Invalid arguments! Show help with -h argument.")
9Aug/112

BATCH – Single Instance

Posted by Dark#Basics

Batch-script for single instance verification, can be used in combination with Task Schedular.

Select All Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
@echo off
REM ProcessName
SET PROCESS=notepad.exe
REM Path of the program
SET PROGRAMPATH=C:\WINDOWS\System32\notepad.exe
REM Check the amount of running processes
tasklist /FI "IMAGENAME eq %PROCESS%" | find /I /C "%PROCESS%" >> PCOUNT.DAT
SET /P PCOUNT=< PCOUNT.DAT
del PCOUNT.DAT
REM If 0, start instance
IF %PCOUNT% EQU 0 ( "%PROGRAMPATH%" )
REM If 2 or more, kill instances and start new instance
IF %PCOUNT% GEQ 2 ( TASKKILL /F /IM %PROCESS% /T && "%PROGRAMPATH%")


9Aug/110

VBS – Add Favorite IE

Posted by Dark#Basics

Simple VB-script that adds the specified URL to the favorite list, can be used in combination with logon-scripts, Group Policies,...

Select All Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
REM Add Favorite in Internet Explorer
 
Const ADMINISTRATIVE_TOOLS = 6
 
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(ADMINISTRATIVE_TOOLS)
Set objFolderItem = objFolder.Self
 
Set objShell = WScript.CreateObject("WScript.Shell")
strDesktopFld = objFolderItem.Path
Set objURLShortcut = objShell.CreateShortcut(strDesktopFld & "\Dark Developments.url")
objURLShortcut.TargetPath = "http://www.darkdevelopments.org"
objURLShortcut.Save
4Jul/110

VBS – Adding Printers

Posted by Dark#Basics

Because the forums are still down I'll use the blog to give some information to the public.

Today I had some issues regarding printers. Because all of our printers are spread over 4 servers and I want to be able to distribute 64 & 32bit drivers I've setup a 2008R2 server. But then I needed to add a whole batch of printers. This is the way I did it, using some VBS-scripts that are available in R2 and some basic copy/pasting to a batch file.

Step 1 : use prnport.vbs to define the port.
Step 2 : use prndrvr to add the driver(s).
Step 3 :  use prnmngr so that port and driver is connected/used with the correct printer and give it a generic name for example TYPE_COMPANYDEPARTMENT
Step 4 : use prncnfg to define additional parameters (shared, published, sharename,...)

Select All Code:
1
2
3
4
5
6
7
8
'Add Port - http://technet.microsoft.com/en-us/library/bb490975.aspx 
prnport.vbs -a -r IP_10.0.10.5 -h 10.0.10.5 -o raw -n 9100
'Add Driver - http://technet.microsoft.com/en-us/library/bb490972.aspx 
prndrvr -a "Canon iR 3025 PCL 6" -h C:\Drivers\Canon\IR3025\X64\ -i IN40VCB.inf
'Define Printer & Driver - http://technet.microsoft.com/en-us/library/bb490974.aspx 
prnmngr.vbs -a -p "CANONiR3025_DEPXYZ" -m "Canon iR 3025 PCL 6" -r IP_10.0.10.5
'Set Properties (Sharename, Location, Shared, Published) - http://technet.microsoft.com/en-us/library/bb490971.aspx 
prncnfg.vbs -t -p "CANONiR3025_DEPXYZ" -h "Canon Invoice Printer DEP XYZ" -l "1FLOOR DEPXYZ" +shared +published