Wednesday, September 06, 2017

Windows 7 password hack

Here's a cool hack doing the rounds which I've tested several times already (I do IT stuff in my spare time which includes lost passwords and data recovery).
If you've forgotten your Windows login password, you can reset it using the "net" command.
I have used this on Windows 7 Home Premium 32 & 64 bit.

First of all some "net" usage ...

List users:

>net user

change password to pa55w0d for the user Ploppy pants :
>net user "Ploppy pants" pa55w0d
(note the use of quotes. This is only because there is a space in the user name Ploppy pants)

Activate the administrator account:
>net user administrator /active:yes

You can also prompt for the password using * :

>net user "Ploppy pants" *

Ok so that's all very well, but you can't get into command prompt to do this if you can't log in.


Here's the cool hacky bit.

In a nutshell we are going to replace the "Ease of access" (EoA) utility with command prompt.
See, when you get the login prompt there is a button (normally bottom left corner) that looks like this

Which normally opens the EoA dialogue. What we do is change the executable which is :

c:/windows/system32/Utilman.exe
to
c:/windows/system32/cmd.exe
So when you press the EoA button you'll get the command prompt where you can change the password.


You still need to access the file system to do so, which you can do with a recovery disk/usb/cd.


One of the recovery options is command prompt. And from there you can do a copy replace like this


>cd c:/windows/system32
>copy Utilman.exe Utilman-bup.exe  (always back your shizz up!)
>copy cmd.exe Utilman.exe
( answer 'yes' to overwrite (if you get access denied then try to delete Utilman.exe first ))


Now in the code example above I assume Windows install directory is C: drive, which it normally is.
But when you're logged into command prompt via the recovery tools, the drive may change to a different letter.

If you run the 'System restore' option, along the way you will see hints of what drive Windows is installed on (according to the recovery function).
Also, instead of swapping cmd with EoA , you could replace the sticky keys dialogue with cmd :

>cd c:/windows/system32
>copy sethc.exe sethc-bup.exe (back it up!)
>copy cmd.exe sethc.exe


When you get the login box press Shift fives times ;)




Friday, October 21, 2016

Newline character in prompt (or bat files) for Windows 7

So I found a rather old blog post back when I was doing admin stuffs on a Windows 2000 server and XP (which was flashy at the time).
Basically I had a bat file that would "net send" to users that I specified on the network, and to fancy it up a bit I wanted line breaks in the message. It took a few days of research to find the answer and when I did I blogged it. It went something like this :

Wah? Yeah, thought I'd put this information here so I don't loose it! And it took me ages to find this info, so use it wisely.
In cmd prompt (tested on Win2k and WinXP) line you can simulate a return carriage or new line with CTRL-T
If you were to drop into cmd, and type :
net send %computername% "LINE ONELINE TWO"
(replacing by pressing CTRL and T together)
You'll get a pop-up message with 'LINE ONE' on one line and 'LINE TWO' on the next.
ALT-2+0 (hold down ALT and press 2 then 0 on the number pad) does the same thing as CTRL-T
To add this to a batch file use edit.com. It allows you to press CTRL-T.
:monkey:


So yeah, way back when aye. Ok so some character in the post are gone burger (found it on the Wayback Machine as an RSS feed yah!)
This trick no longer works in Windows 7.
However I believe the ALT-010 or ALT-10 works in Windows 8 but I haven't tested because I'm staying away from 8 & 10.

So yeah, on Windows 7 ? Here's the results of my latest research...

set n=^&echo.

Now you can use %n% to output a line feed.

echo Line one%n%Line two

Woah really?

set is used to "set" variables. We are setting "n" to equal "^&echo."

^ is a "ignore first thing after me, or escape the next thingy"

So ^ ignores the &

The & is used to string commands together (like echo hi & echo there)


So the ^ escapes or ignores the & but it's still stringing commands.
You can use ^ to write a string on two multiple line ( look it up :) )
The echo. echos a blank line (you can have lots of different characters after the echo (with no space))


Aiigh are we all clear now?
Good!

If you're writing a bat file drop the

set n=^&echo.

near the top somewhere so you can use %n% all throughout your codey scripty thing.





(yes you may)

Saturday, September 24, 2016

Windows RUN dialogue ... run command and display in notepad

The windows run dialogue :

[what the title says]
 













You can fish this up by pressing the windows key and r at the same time. Or find it in your start menu, labeled "Run...".
Obviously on "cool" windows and not "user-friendly ui" windows 8 or 10 ... as I don't use them. If your doing dev. stuff, well maybe stick to windows with a proper ui)


These are my notes on how to run a command in the windows run dialogue (windows key + r) and send (pipe) the results to notepad.
This is handy for those wanting to "ipconfig" and not have to open cmd first.
The thing to remember here is the run dialogue is not the same as command line.
So a simple > or | doesn't work straight off the bat. 
You can only use those in cmd.
If you open cmd and then call your command from there, you can pipe, write or get data.
You can call "cmd" on the windows run dialogue.


echo test message > text.txt | notepad text.txt
this doesnt work with w+r but does work on cli
...so...

cmd /k ipconfig

this opens cmd and does ipconfig

cmd /c ipconfig
this opens cmd , does ipconfig and then the console window closes immediately

...so...


cmd /c echo test message > text.txt | notepad text.txt
opens cmd , does an "echo test message" that is sent to text.txt , which is piped to notepad , after closing notepad the console will close

a step further - lets remove the text.txt file after you close notepad :)
cmd /c echo test message > text.txt | notepad text.txt & del text.txt


so here's a quick ipconfig to notepad :
cmd /c ipconfig > x | notepad x & del x


or send ipconfig to cmd and do a pause , console closes after any key is pressed (aaaaanny key (as long as its 0-9 a-z (:))))
cmd /c ipconfig & pause






Monday, July 11, 2016

Cannot delete CON or AUX files .... yah Windows!!

So I had a copy of Cygwin running (for local web server stuff) and once I had done with it tried to delete it.
But no! Windows cannot find the file CON.cif .... oh what? I can see it. It's just there - look Windows, right in front of you!
Anyway, I did come across this in the past with the 'ole CON file thingy. And remembered Windows has several reserved file names :
CLOCK$, CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9 LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, LPT9

How stupid! Can't you give them device looking names like //CON and //LPT1 etc?? Grrrr.

Ok so if you've ever had this problem, and you've tried cmd line, third party tools, chkdsk, rd, ren, file permissions, Safe-mode, Booting to DOS (lol)  .... basically  everything with no luck.
Well I found this little tidbit online :

rd \\.\c:\documents\con /S /Q
or
del \\?\C:\cygwin\src\linux-3.7.1\drivers\gpu\drm\nouveau\core\subdev\i2c\aux.c

These are "remove dir" and "delete" methods, specifying the current computer first ( \\. or \\? ).
I think this also means that you could delete the file from another PC on the same network :) 

Hope this saves someone!





Wednesday, May 25, 2016

OpenID in Perl for Steam API

For my first game (soon to be posted here) !CARDIGAN! I needed to hook into the Steam API, and also give players the option to log in via Steam (in fact it's the only login method I want them to use).

I'm a Perl coder, but only found working examples of logging into OpenID using PHP. Which was a good start, and I even had Perl and PHP talking nicely to each other, but I really didn't want PHP on my server (that's another story for another time).

So, I got my head down and just did it. Perling away like a little .... erm .... Perl coding person. (yeah that's the perfect analogy!)

I went with Net::OpenID::Consumer in the end, because it looked easy to implement.

Nek minit! (soz) Actually more like nek day.
After a day of fiddling around, with little online documentation and no real examples to implement OpenID with Steam (in Perl), I got it working.

The last thing that I did that finally got things rolling' was to force upgrade the module, so it currently stands as :
Net::OpenID::Consumer::VERSION 1.18
I was having issues with an earlier version 1.03.
Oh BTW this is on 64bit CentOS 6.7 with Perl v5.10.1

Make sure you have all the dependencies with latest versions installed.


#!perl # yeah IKR! i use set perl as a symlink to the actual executable, my code can be directly copied between environments :)
use CGI::Carp qw(fatalsToBrowser);# add your own stricts and stuff up here
use Net::OpenID::Consumer;
use LWPx::ParanoidAgent;
use Cache::File;
use CGI;
my$steamlogin="https://steamcommunity.com/openid/?l=english"; # this is the URL that sends you to the Steam Community login - use this, don't change it
my$dns=$ENV{SERVER_NAME}; # feel free to hard-code your domain here (using server envs make the code more adaptable)
my$cgi=CGI->new();
my$csr=Net::OpenID::Consumer->new(
 ua=>LWPx::ParanoidAgent->new,
 cache=>Cache::File->new(cache_root=>"/tmp/mycache"),
 args=>$cgi,
 consumer_secret=>$key, # put your Steam API key here (in quotes)
 required_root=>"http://$dns/", # this is the root of your site that is doing the OpenID call ( i.e. # http://mywebsite.co.nz/ )
 =>[max_encrypt=>1,session_no_encrypt_https=>1,], # if you get an error complaining about no option assoc_options, then update your modules
);
if($cgi->param("openid.mode")){# this is just a test to see if the cipt has come from the Steam login page (i.e. the response)
print $cgi->header();# it's very unlinke me to use CGI but this is rushed code
 $csr->handle_server_response(
  not_openid=>sub{
   print"Invalid OpenID message";
  },
  setup_required=>sub{
   my$setup_url=shift;
   print"User not set up correctly";
  },
  cancelled=>sub {
   print"Login canceled";
  },
  verified=>sub{
   my$vident=shift;
   my$url=$vident->url;
   print"Your verification URL : $url";
  },
  error => sub {
   print $csr->err;
  }
 );
 exit;
}else{
 my$claimed_identity=$csr->claimed_identity($steamlogin);
 unless($claimed_identity){print "Invalid OpenID?".$csr->err;}
 my$check_url=$claimed_identity->check_url(
  delayed_return=>1,
  return_to=>"http://${dns}$ENV{SCRIPT_NAME}",#this is the URL of this script (hardcode it if you must)
  trust_root=>"http://$dns/", # same as "required_root"
 );
 print"Status: 302 Found\nContent-type: text/html\nLocation: $check_url\n\n<a href='$check_url'>$check_url</a>";#this sends off the deets to the steam login page
}


This is a first draft (but working prototype).
Once verified you can use one of the many Perl web Steam APIs to get the user data,
and create a session file, cookie session or whatever.

Also don't forget to link to your script with an official Steam API button. ( see https://steamcommunity.com/dev )

So, yeah. I hope someone finds this code useful as I had next to no help online.





Tuesday, January 26, 2010

TiPs

Add this your Windows XP batch in place if ye olde sleep or wait commands,
@ping 127.0.0.1 -n 2 -w 1000 > nul
@ping 127.0.0.1 -n %1% -w 1000> nul