diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..412eeda --- /dev/null +++ b/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b9d6bd9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,215 @@ +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + + +################# +## Visual Studio +################# + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml +*.pubxml + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +#packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + +############# +## Windows detritus +############# + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac crap +.DS_Store + + +############# +## Python +############# + +*.py[co] + +# Packages +*.egg +*.egg-info +dist/ +build/ +eggs/ +parts/ +var/ +sdist/ +develop-eggs/ +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox + +#Translations +*.mo + +#Mr Developer +.mr.developer.cfg diff --git a/README.md b/README.md new file mode 100644 index 0000000..8a2b76c --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +WinSCP Password Extractor/Decrypter/Revealer +============================================= + +WinSCP stores ssh session passwords in an encrypted format in the windows registry. If you have passwords saved in WinSCP sessions but have forgotten them, use this tool to get it back. + +Steps +----- +1. Open your windows registry (you can do this by hitting Win + R and entering `regedit`) +1. Navigate to [HKEY_CURRENT_USER\\Software\\Martin Prikryl\\WinSCP 2\\Sessions] to get the hostname, username and encrypted password +1. Take a command prompt and run winscppasswd passing hostname, username and encrypted password as parameter. + +```sh +winscppasswd.exe +``` +Decrypted password will be shown on the command prompt + +About +------ +This utility was written to "scratch my own itch" of me constantly forgetting my saved passwords. There are couple of third party tools available that can decrypt the password, but I wasn't overly joyed at the concept of handing over my password to an unkonwn tool downloaded from the internet. So I decided to write my own. + +You can download a ready made binary from "Releases" section in GitHub. But you are welcome to compile the source yourself if you don't trust binary files. + +This is written in Go lang. Head over to http://golang.org/ to download the compiler. diff --git a/main.go b/main.go new file mode 100644 index 0000000..d0fee6b --- /dev/null +++ b/main.go @@ -0,0 +1,74 @@ +package main + +import ( + "fmt" + "os" + "runtime" + "strconv" +) + +const ( + PW_MAGIC = 0xA3 + PW_FLAG = 0xFF +) + +func main() { + args := os.Args[1:] + if len(args) != 3 { + fmt.Println("WinSCP stored password finder") + fmt.Println("Open regedit and navigate to [HKEY_CURRENT_USER\\Software\\Martin Prikryl\\WinSCP 2\\Sessions] to get the hostname, username and encrypted password\n") + if runtime.GOOS == "windows" { + fmt.Println("Usage winscppasswd.exe ") + } else { + fmt.Printf("Usage ./winscppasswd ") + } + return + } + fmt.Println(decrypt(args[0], args[1], args[2])) +} + +func decrypt(host, username, password string) string { + key := username + host + passbytes := []byte{} + for i := 0; i < len(password); i++ { + val, _ := strconv.ParseInt(string(password[i]), 16, 8) + passbytes = append(passbytes, byte(val)) + } + var flag byte + flag, passbytes = dec_next_char(passbytes) + var length byte = 0 + if flag == PW_FLAG { + _, passbytes = dec_next_char(passbytes) + + length, passbytes = dec_next_char(passbytes) + } else { + length = flag + } + toBeDeleted, passbytes := dec_next_char(passbytes) + passbytes = passbytes[toBeDeleted*2:] + + clearpass := "" + var ( + i byte + val byte + ) + for i = 0; i < length; i++ { + val, passbytes = dec_next_char(passbytes) + clearpass += string(val) + } + + if flag == PW_FLAG { + clearpass = clearpass[len(key):] + } + return clearpass +} + +func dec_next_char(passbytes []byte) (byte, []byte) { + if len(passbytes) <= 0 { + return 0, passbytes + } + a := passbytes[0] + b := passbytes[1] + passbytes = passbytes[2:] + return ^(((a << 4) + b) ^ PW_MAGIC) & 0xff, passbytes +}