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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
|
/*
* Medusa Parallel Login Auditor
*
* Copyright (C) 2006 Joe Mondloch
* JoMo-Kun / jmk@foofus.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation
*
* 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.
*
* http://www.gnu.org/licenses/gpl.txt
*
* This program is released under the GPL with the additional exemption
* that compiling, linking, and/or using OpenSSL is allowed.
*
*/
#ifndef _MEDUSA_H
#define _MEDUSA_H
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <time.h>
#include <math.h>
#include "medusa-trace.h"
#include "medusa-net.h"
#include "medusa-thread-pool.h"
#include "medusa-thread-ssl.h"
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_LIBSSL
#include <openssl/crypto.h>
#endif
#define PROGRAM "Medusa"
#ifndef VERSION
#define VERSION "1.0"
#endif
#define AUTHOR "JoMo-Kun / Foofus Networks"
#define EMAIL "<jmk@foofus.net>"
#define WWW "http://www.foofus.net"
#define SUCCESS 0
#define FAILURE -1
#define FALSE 0
#define TRUE 1
/* GLOBAL VARIABLES */
FILE *pOutputFile;
pthread_mutex_t ptmFileMutex;
int iVerboseLevel; // Global control over general message verbosity
int iErrorLevel; // Global control over error debugging verbosity
//#define MAX_BUF (16 * 1024)
#define MAX_BUF 16384
/* Older Solaris doesn't seem to define INADDR_NONE */
#ifndef INADDR_NONE
#define INADDR_NONE ((unsigned long) -1
#endif
/* Cygwin doesn't seem to define INET_ADDRSTRLEN */
#ifndef INET_ADDRSTRLEN
#define INET_ADDRSTRLEN 16
#endif
// Number of seconds that idle threads can linger before exiting, when no tasks
// come in. The idle threads can only exit if they are extra threads, above the
// number of minimum threads.
#define POOL_THREAD_LINGER 1
#define FREE(x) \
if (x != NULL) { \
free(x); \
x = NULL; \
}
#define L_UNSET 0
#define L_SINGLE 1
#define L_FILE 2
#define L_COMBO 3
#define L_PWDUMP 4
typedef struct __sPass {
struct __sPass *psPassNext;
char *pPass;
} sPass;
/* Used in __sUser to define progress of an individual username audit */
#define PL_UNSET 0
#define PL_NULL 1
#define PL_USERNAME 2
#define PL_LOCAL 3
#define PL_GLOBAL 4
#define PL_DONE 5
#define PASS_AUDIT_COMPLETE 6
typedef struct __sUser {
struct __sUser *psUserNext;
char *pUser;
struct __sPass *psPass;
struct __sPass *psPassCurrent;
struct __sPass *psPassPrevTmp;
char *pPass;
int iPassCnt;
int iLoginsDone;
int iPassStatus;
int iId;
} sUser;
/* Used in __sHost to define progress of the audit of the host's users */
#define UL_UNSET 0
#define UL_NORMAL 1
#define UL_MISSED 2
#define UL_DONE 3
#define UL_ERROR 4
typedef struct __sHost {
struct __sHost *psHostNext;
char *pHost;
int iUseSSL; // use SSL
int iPortOverride; // use this port instead of the module's default port
int iTimeout; // Number of seconds to wait before a connection times out
int iRetryWait; // Number of seconds to wait between retries
int iRetries; // Number of retries to attempt
sUser *psUser;
sUser *psUserCurrent;
sUser *psUserPrevTmp;
int iUserCnt;
int iUserPassCnt;
int iUsersDone; // number of users tested
int iUserStatus;
int iId;
} sHost;
/* Used in __sCredentialSet to relay information to module regarding user */
#define CREDENTIAL_SAME_USER 1
#define CREDENTIAL_NEW_USER 2
#define CREDENTIAL_DONE 3
typedef struct __sCredentialSet {
struct __sCredentialSet *psCredentialSetNext;
struct __sUser *psUser;
char *pPass;
int iStatus;
} sCredentialSet;
typedef struct __sServer {
struct __sAudit *psAudit;
struct __sHost *psHost;
char *pHostIP;
int iValidPairFound;
int iId;
int iLoginCnt; // total number of logins performed concurrently against specific server
int iLoginsDone; // number of logins performed by all threads under this server
sCredentialSet *psCredentialSetMissed;
sCredentialSet *psCredentialSetMissedCurrent;
sCredentialSet *psCredentialSetMissedTail;
int iCredentialsMissed;
pthread_mutex_t ptmMutex;
} sServer;
#define LOGIN_RESULT_UNKNOWN 1
#define LOGIN_RESULT_SUCCESS 2
#define LOGIN_RESULT_FAIL 3
#define LOGIN_RESULT_ERROR 4
typedef struct __sLogin {
struct __sServer *psServer;
struct __sUser *psUser;
int iResult;
char *pErrorMsg;
int iId;
int iLoginsDone; // number of logins performed by this thread
} sLogin;
#define AUDIT_IN_PROGRESS 0
#define AUDIT_COMPLETE 1
#define LIST_IN_PROGRESS 0
#define LIST_COMPLETE 1
#define FOUND_PAIR_EXIT_HOST 1
#define FOUND_PAIR_EXIT_AUDIT 2
#define PARALLEL_LOGINS_USER 1
#define PARALLEL_LOGINS_PASSWORD 2
#define AUDIT_ABORT 1
typedef struct __sAudit {
char *pOptHost; // user specified host or host file
char *pOptUser; // user specified username or username file
char *pOptPass; // user specified password or password file
char *pOptCombo; // user specified combo host/username/password file
char *pOptOutput; // user specified output file
char *pOptResume; // user specified resume command
char *pModuleName; // current module name
char *pGlobalHost;
char *pGlobalUser;
char *pGlobalPass;
char *pGlobalCombo;
char *pHostFile;
char *pUserFile;
char *pPassFile;
char *pComboFile;
int iHostCnt; // total number of hosts supplied for testing
int iUserCnt; // total number of users supplied for testing
int iPassCnt; // total number of passwords supplied for testing
int iComboCnt; // total number of entries in combo file
int iServerCnt; // total number of hosts scanned concurrently
int iLoginCnt; // total number of logins performed concurrently
int iHostsDone; // number of hosts tested
int iPortOverride; // use this port instead of the module's default port
int iUseSSL; // enable SSL
int iTimeout; // Number of seconds to wait before a connection times out
int iRetryWait; // Number of seconds to wait between retries
int iRetries; // Number of retries to attempt
int iSocketWait; // Number of usec to wait when module calls medusaCheckSocket function
int HostType;
int UserType;
int PassType;
int iShowModuleHelp; // Flag used to show individual module help
char *pComboEntryTmp; // used to managed processing of user supplied files
int iHostListFlag;
int iUserListFlag;
int iAuditFlag; /* Tracks loading of user supplied information */
int iPasswordBlankFlag; /* Submit a blank password for each user account */
int iPasswordUsernameFlag; /* Submit a password matching the username for each user account */
int iFoundPairExitFlag; /* When a valid login pair is found, end scan of host or of complete audit */
int iParallelLoginFlag; /* Parallel logins by user or password */
int iValidPairFound;
int iStatus; /* Flag to indicate to threads that audit is aborting */
sHost *psHostRoot;
thr_pool_t *server_pool;
pthread_mutex_t ptmMutex;
} sAudit;
typedef struct __sModuleStart
{
char* szModuleName;
sLogin* pLogin;
int argc;
char** argv;
} sModuleStart;
void listModules(char* arrPaths[], int nTerminateNow);
int invokeModule(char* pModuleName, sLogin* pLogin, int argc, char* argv[]);
int getNextCredSet(sLogin *_psLogin, sCredentialSet *_psCredSet);
void setPassResult(sLogin *_psLogin, char *_pPass);
int addMissedCredSet(sLogin *_psLogin, sCredentialSet *_psCredSet);
#endif
|