From 2f93c0f45276c71399418afb0554137f2a30eeb8 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Wed, 11 Jan 2017 15:28:18 +0100 Subject: [PATCH] winpr-hash: cleanup cmd line and add man page * add a initial man page * clean up the command line a little bit (basically error messages) --- winpr/tools/.gitignore | 1 + winpr/tools/hash-cli/CMakeLists.txt | 1 + winpr/tools/hash-cli/hash.c | 44 +++++++++++++++++++++--------------- winpr/tools/hash-cli/winpr-hash.1.in | 42 ++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 18 deletions(-) create mode 100644 winpr/tools/hash-cli/winpr-hash.1.in diff --git a/winpr/tools/.gitignore b/winpr/tools/.gitignore index daf1263..a6e5f22 100644 --- a/winpr/tools/.gitignore +++ b/winpr/tools/.gitignore @@ -1,2 +1,3 @@ makecert-cli/winpr-makecert hash-cli/winpr-hash +hash-cli/winpr-hash.1 diff --git a/winpr/tools/hash-cli/CMakeLists.txt b/winpr/tools/hash-cli/CMakeLists.txt index 7b9195a..c16f860 100644 --- a/winpr/tools/hash-cli/CMakeLists.txt +++ b/winpr/tools/hash-cli/CMakeLists.txt @@ -50,3 +50,4 @@ if (WITH_DEBUG_SYMBOLS AND MSVC) endif() set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Tools") +configure_file(winpr-hash.1.in ${CMAKE_CURRENT_BINARY_DIR}/winpr-hash.1) diff --git a/winpr/tools/hash-cli/hash.c b/winpr/tools/hash-cli/hash.c index d12c71c..e295a7c 100644 --- a/winpr/tools/hash-cli/hash.c +++ b/winpr/tools/hash-cli/hash.c @@ -44,6 +44,13 @@ * */ +void usage_and_exit() +{ + printf("winpr-hash: NTLM hashing tool\n"); + printf("Usage: winpr-hash -u -p [-d ] [-f <_default_,sam>] [-v <_1_,2>]\n"); + exit(1); +} + int main(int argc, char* argv[]) { int index = 1; @@ -65,8 +72,8 @@ int main(int argc, char* argv[]) if (index == argc) { - printf("missing domain\n"); - exit(1); + printf("missing domain\n\n"); + usage_and_exit(); } Domain = argv[index]; @@ -77,8 +84,8 @@ int main(int argc, char* argv[]) if (index == argc) { - printf("missing username\n"); - exit(1); + printf("missing username\n\n"); + usage_and_exit(); } User = argv[index]; @@ -89,8 +96,8 @@ int main(int argc, char* argv[]) if (index == argc) { - printf("missing password\n"); - exit(1); + printf("missing password\n\n"); + usage_and_exit(); } Password = argv[index]; @@ -101,14 +108,17 @@ int main(int argc, char* argv[]) if (index == argc) { - printf("missing version\n"); - exit(1); + printf("missing version parameter\n\n"); + usage_and_exit(); } version = atoi(argv[index]); if ((version != 1) && (version != 2)) - version = 1; + { + printf("unkown version %d \n\n", version); + usage_and_exit(); + } } else if (strcmp("-f", argv[index]) == 0) { @@ -116,8 +126,8 @@ int main(int argc, char* argv[]) if (index == argc) { - printf("missing format\n"); - exit(1); + printf("missing format\n\n"); + usage_and_exit(); } if (strcmp("default", argv[index]) == 0) @@ -127,9 +137,7 @@ int main(int argc, char* argv[]) } else if (strcmp("-h", argv[index]) == 0) { - printf("winpr-hash: NTLM hashing tool\n"); - printf("Usage: winpr-hash -u -p [-d ] -f -v <1,2>\n"); - exit(1); + usage_and_exit(); } index++; @@ -137,8 +145,8 @@ int main(int argc, char* argv[]) if ((!User) || (!Password)) { - printf("missing username or password\n"); - exit(1); + printf("missing username or password\n\n"); + usage_and_exit(); } UserLength = strlen(User); @@ -149,8 +157,8 @@ int main(int argc, char* argv[]) { if (!Domain) { - printf("missing domain\n"); - exit(1); + printf("missing domain (version 2 requires a domain to specified)\n\n"); + usage_and_exit(); } NTOWFv2A(Password, PasswordLength, User, UserLength, Domain, DomainLength, NtHash); diff --git a/winpr/tools/hash-cli/winpr-hash.1.in b/winpr/tools/hash-cli/winpr-hash.1.in new file mode 100644 index 0000000..f801eca --- /dev/null +++ b/winpr/tools/hash-cli/winpr-hash.1.in @@ -0,0 +1,42 @@ +.TH winpr-hash 1 2017-01-11 "@FREERDP_VERSION_FULL@" "FreeRDP" +.SH NAME +winpr-hash \- NTLM hashing tool +.SH SYNOPSIS +.B winpr-hash +\fB-u\fP username +\fB-p\fP password +[\fB-d\fP domain] +[\fB-f\fP { \fIdefault\fP | sam }] +[\fB-v\fP { \fI1\fP | 2 }] +.SH DESCRIPTION +.B winpr-hash +is a small utility that can be used to create a NTLM hash form a username and password pair. The created hash can be outputed as plain hash or in SAM format. +.SH OPTIONS +.IP "-u username" +The username to use. +.IP "-p password" +Password to use. +.IP "-d domain" +A optional parameter to specify the domain of the user. +.IP "-f format" +Specify the output format. The \fIdefault\fP outputs only the plain NTLM +hash. The second output format available is \fIsam\fP which outputs the +created hash in a format that it can be used in SAM file: + +user:domain::hash::: +.IP "-v version" +Version allows it to specify the NTLM version to use. The default is to use version 1. In case +version 2 is used a domain needs to be specified. +.SH EXAMPLES +winpr-hash -u \fIuser\fP -p \fIpassword\fP -d \fIdomain\fP -f \fIsam\fP -v \fI2\fP + +Create a version \fI2\fP NTLM hash for \fIuser\fP with \fIdomain\fP and \fIpassword\fP and output it in \fIsam\fP format. +.SH EXIT STATUS +.TP +.B 0 +Successful program execution. +.TP +.B 1 +Missing or invalid arguments. +.SH AUTHOR +FreeRDP -- 2.7.4