-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchallenge1.bat
154 lines (108 loc) · 2.7 KB
/
challenge1.bat
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
:: challenge1.bat
:: Determine who the script is running as
:: Get list of all users, determine all administrators
:: Create new user, add them to administrators group
:: Launch shell as the new user, use whoami to verify
:: Clean up, remove new user from administrators group
:: Delete new user from system
:: Print list of all users & administrators group membership
:: along the way so we can see the changes happening
:: This is ugly, I don't know how to batch ... better solutions?
:: How do you var=$(command) like in bash?
@echo off
:: Default Vars
set newuser=Test
set newuserpass=correct horse battery staple
:: Determine what user & domain this script is running as
:: from cmd.exe use "set username" to print the enviromental variable
:: In a batch script, these enviromental variables are already set
:: we just need to access them using %ENV_VAR%
set user=%USERNAME%
echo Username: %user%
set domain=%USERDOMAIN%
echo Domain: %domain%
echo.
echo.
echo.
echo Whoami:
:: "whoami" is also possible
set whoami=whoami
call %whoami%
echo.
echo.
echo.
echo All local users:
:: Get list of all users using "net user" cmd
set allusers=net user
call %allusers%
echo.
echo.
echo.
echo Users in the Administrators group:
:: List all users in the administrators group
set adminusers=net localgroup administrators
call %adminusers%
echo.
echo.
echo.
echo Creating Test User: %newuser%
:: Create a new user
set createuser=net user %newuser% "%newuserpass%" /add /y
call %createuser%
echo.
echo.
echo.
echo Adding User %newuser% to Administrators group
:: Adding new user to Administrators group
set addusertogrp=net localgroup administrators %newuser% /add
call %addusertogrp%
echo.
echo.
echo.
echo All local users:
:: Get list of all users using "net user" cmd
set allusers=net user
call %allusers%
echo.
echo.
echo.
echo Users in the Administrators group:
:: List all users in the administrators group
set adminusers=net localgroup administrators
call %adminusers%
echo.
echo.
echo.
echo Launch cmd.exe as user %newuser
call runas /u:%newuser% cmd.exe & pause
echo.
echo.
echo.
echo Removing User %newuser% from Administrators group
:: Removing new user from Administrators group
set removeuserfromgrp=net localgroup administrators %newuser% /del
call %removeuserfromgrp%
echo.
echo.
echo.
echo Deleting Test User: %newuser%
:: Deleting new user
set deleteuser=net user %newuser% /del /y
call %deleteuser%
echo.
echo.
echo.
echo All local users:
:: Get list of all users using "net user" cmd
set allusers=net user
call %allusers%
echo.
echo.
echo.
echo Users in the Administrators group:
:: List all users in the administrators group
set adminusers=net localgroup administrators
call %adminusers%
echo.
echo.
echo.