| 1 | /* |
| 2 | * |
| 3 | * Ophcrack is a Lanmanager/NTLM hash cracker based on the faster time-memory |
| 4 | * trade-off using rainbow tables. |
| 5 | * |
| 6 | * Created with the help of: Maxime Mueller, Luca Wullschleger, Claude |
| 7 | * Hochreutiner, Andreas Huber and Etienne Dysli. |
| 8 | * |
| 9 | * Copyright (c) 2008 Philippe Oechslin, Cedric Tissieres, Bertrand Mesot |
| 10 | * |
| 11 | * Ophcrack is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * Ophcrack is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with Ophcrack; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 | * |
| 25 | * This program is released under the GPL with the additional exemption |
| 26 | * that compiling, linking, and/or using OpenSSL is allowed. |
| 27 | * |
| 28 | * |
| 29 | * |
| 30 | * |
| 31 | */ |
| 32 | #include <assert.h> |
| 33 | #include <QString> |
| 34 | |
| 35 | #include "hashmodel.h" |
| 36 | #include "list.h" |
| 37 | #include "hash.h" |
| 38 | #include "misc.h" |
| 39 | //--------------------------------------------------------------------------- |
| 40 | HashModel::HashModel(QObject *parent, bool x) : QStandardItemModel(0, 6, parent) { |
| 41 | // Set the header. |
| 42 | |
| 43 | auditMode = x; |
| 44 | if (auditMode) { |
| 45 | setHorizontalHeaderItem(0, new QStandardItem("ID")); |
| 46 | setHorizontalHeaderItem(1, new QStandardItem("Cracked")); |
| 47 | setHorizontalHeaderItem(2, new QStandardItem("Time")); |
| 48 | setHorizontalHeaderItem(3, new QStandardItem("Table")); |
| 49 | setHorizontalHeaderItem(4, new QStandardItem("Length")); |
| 50 | setHorizontalHeaderItem(5, new QStandardItem("Category")); |
| 51 | } else { |
| 52 | setHorizontalHeaderItem(0, new QStandardItem("User")); |
| 53 | setHorizontalHeaderItem(1, new QStandardItem("LM Hash")); |
| 54 | setHorizontalHeaderItem(2, new QStandardItem("NT Hash")); |
| 55 | setHorizontalHeaderItem(3, new QStandardItem("LM Pwd 1")); |
| 56 | setHorizontalHeaderItem(4, new QStandardItem("LM Pwd 2")); |
| 57 | setHorizontalHeaderItem(5, new QStandardItem("NT Pwd")); |
| 58 | } |
| 59 | |
| 60 | for (int i=0; i<columnCount(); ++i) { |
| 61 | QStandardItem *item = horizontalHeaderItem(i); |
| 62 | item->setTextAlignment(Qt::AlignCenter); |
| 63 | } |
| 64 | |
| 65 | unameVisible = 0; |
| 66 | } |
| 67 | //--------------------------------------------------------------------------- |
| 68 | void HashModel::insertHash(hash_t *hsh) { |
| 69 | assert(hsh != 0); |
| 70 | |
| 71 | int nrows = rowCount(); |
| 72 | int ncols = columnCount(); |
| 73 | int id = hsh->id; |
| 74 | |
| 75 | QStandardItem *item = itemFromId.value(id); |
| 76 | |
| 77 | if (item == 0) { |
| 78 | for (int i=ncols-1; i>=0; --i) { |
| 79 | item = new QStandardItem(); |
| 80 | item->setData(int(id), Qt::UserRole); |
| 81 | setItem(nrows, i, item); |
| 82 | } |
| 83 | |
| 84 | itemFromId.insert(id, item); |
| 85 | } |
| 86 | |
| 87 | updateHash(hsh); |
| 88 | } |
| 89 | //--------------------------------------------------------------------------- |
| 90 | void HashModel::insertHashes(list_t *hashes) { |
| 91 | list_nd_t *nd; |
| 92 | |
| 93 | for (nd = hashes->head; nd != 0; nd = nd->next) { |
| 94 | hash_t *hsh = (hash_t*)nd->data; |
| 95 | insertHash(hsh); |
| 96 | } |
| 97 | } |
| 98 | //--------------------------------------------------------------------------- |
| 99 | void HashModel::updateHash(hash_t *hsh, bool notFound) { |
| 100 | int id = hsh->id; |
| 101 | QStandardItem *root = itemFromId.value(id); |
| 102 | |
| 103 | if (root == 0) return; |
| 104 | |
| 105 | int row = indexFromItem(root).row(); |
| 106 | |
| 107 | if (!auditMode) { |
| 108 | |
| 109 | // Set the user name. |
| 110 | |
| 111 | if (unameVisible) |
| 112 | item(row, 0)->setText("*****"); |
| 113 | else |
| 114 | item(row, 0)->setText(QString::fromUtf8(hsh->info)); |
| 115 | |
| 116 | // Set the hash and password. |
| 117 | |
| 118 | int idx_txt = 0, idx_pwd = 0; |
| 119 | |
| 120 | switch (hsh->kind) { |
| 121 | case lm1: |
| 122 | idx_txt = 1; |
| 123 | idx_pwd = 3; |
| 124 | break; |
| 125 | |
| 126 | case lm2: |
| 127 | idx_txt = 1; |
| 128 | idx_pwd = 4; |
| 129 | break; |
| 130 | |
| 131 | case nt: |
| 132 | idx_txt = 2; |
| 133 | idx_pwd = 5; |
| 134 | break; |
| 135 | } |
| 136 | |
| 137 | item(row, idx_txt)->setText(hsh->str); |
| 138 | |
| 139 | if (hsh->pwd[0] != 0) { |
| 140 | item(row, idx_pwd)->setText(hsh->pwd); |
| 141 | item(row, idx_pwd)->setForeground(QColor(0, 0, 0)); |
| 142 | } |
| 143 | |
| 144 | else if (hsh->done > 0) { |
| 145 | item(row, idx_pwd)->setText("empty"); |
| 146 | item(row, idx_pwd)->setForeground(QColor(0, 0, 255)); |
| 147 | } |
| 148 | |
| 149 | else if (hsh->done <= 0) { |
| 150 | if (notFound) { |
| 151 | item(row, idx_pwd)->setText("not found"); |
| 152 | item(row, idx_pwd)->setForeground(QColor(255, 0, 0)); |
| 153 | } else { |
| 154 | item(row, idx_pwd)->setText(""); |
| 155 | item(row, idx_pwd)->setForeground(QColor(0, 0, 0)); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | // If the 1st LM hash is not connected to a NT hash, then we |
| 160 | // display the NT password as empty. |
| 161 | |
| 162 | if (hsh->kind == lm1 && hsh->lmhsh1 == 0) { |
| 163 | item(row, 5)->setText("empty"); |
| 164 | item(row, 5)->setForeground(QColor(0, 0, 255)); |
| 165 | } |
| 166 | } else { |
| 167 | |
| 168 | //audit mode |
| 169 | // Set the ID |
| 170 | char tmp[64] = {0}; |
| 171 | |
| 172 | sprintf(tmp, "%d", hsh->id); |
| 173 | item(row, 0)->setText(tmp); |
| 174 | |
| 175 | item(row, 3)->setForeground(QColor(0, 0, 0)); |
| 176 | item(row, 4)->setForeground(QColor(0, 0, 0)); |
| 177 | item(row, 5)->setForeground(QColor(0, 0, 0)); |
| 178 | |
| 179 | // Only LM1 |
| 180 | if (hsh->kind == lm1 && hsh->lmhsh1 == 0 && hsh->lmhsh2 == 0) { |
| 181 | |
| 182 | if (hsh->done > 0) { |
| 183 | item(row, 1)->setText("Yes"); |
| 184 | |
| 185 | sprintf(tmp, "%d s", hsh->time); |
| 186 | item(row, 2)->setText(tmp); |
| 187 | |
| 188 | item(row, 3)->setText(hsh->table); |
| 189 | |
| 190 | sprintf(tmp, "%d", hsh->length); |
| 191 | item(row, 4)->setText(tmp); |
| 192 | |
| 193 | item(row, 5)->setText(category_string(hsh->category)); |
| 194 | } else { |
| 195 | item(row, 1)->setText("No"); |
| 196 | item(row, 2)->setText(""); |
| 197 | item(row, 3)->setText(""); |
| 198 | item(row, 4)->setText(""); |
| 199 | item(row, 5)->setText(""); |
| 200 | } |
| 201 | } |
| 202 | // LM1 and LM2 with no NT |
| 203 | else if (hsh->kind == lm1 && hsh->lmhsh1 == 0 && hsh->lmhsh2 != 0) { |
| 204 | |
| 205 | if (hsh->done > 0 && hsh->lmhsh2->done >0) { |
| 206 | item(row, 1)->setText("Yes"); |
| 207 | sprintf(tmp, "%d s", (hsh->time > hsh->lmhsh2->time) ? hsh->time : hsh->lmhsh2->time); |
| 208 | item(row,2)->setText(tmp); |
| 209 | snprintf(tmp, 64, "%s / %s", hsh->table, hsh->lmhsh2->table); |
| 210 | item(row,3)->setText(tmp); |
| 211 | sprintf(tmp, "%d", hsh->length+hsh->lmhsh2->length); |
| 212 | item(row,4)->setText(tmp); |
| 213 | item(row,5)->setText(category_string(hsh->category|hsh->lmhsh2->category)); |
| 214 | } else { |
| 215 | item(row, 1)->setText("No"); |
| 216 | item(row,2)->setText(""); |
| 217 | item(row,3)->setText(""); |
| 218 | item(row,4)->setText(""); |
| 219 | item(row,5)->setText(""); |
| 220 | } |
| 221 | } |
| 222 | // NT with LM1 and LM2 |
| 223 | else if (hsh->kind == nt && hsh->lmhsh1 != 0 && hsh->lmhsh2 != 0) { |
| 224 | if (hsh->done > 0) { |
| 225 | item(row, 1)->setText("Yes"); |
| 226 | sprintf(tmp, "%d s", hsh->time); |
| 227 | item(row,2)->setText(tmp); |
| 228 | if (hsh->lmhsh1->table != 0 && hsh->lmhsh2->table != 0) |
| 229 | snprintf(tmp, 64, "%s / %s", hsh->lmhsh1->table, hsh->lmhsh2->table); |
| 230 | else |
| 231 | snprintf(tmp, 64, "%s", hsh->table); |
| 232 | item(row,3)->setText(tmp); |
| 233 | sprintf(tmp, "%d", hsh->length); |
| 234 | item(row,4)->setText(tmp); |
| 235 | item(row,5)->setText(category_string(hsh->category)); |
| 236 | } else { |
| 237 | item(row, 1)->setText("No"); |
| 238 | item(row,2)->setText(""); |
| 239 | item(row,3)->setText(""); |
| 240 | item(row,4)->setText(""); |
| 241 | item(row,5)->setText(""); |
| 242 | } |
| 243 | } |
| 244 | // NT only |
| 245 | else if (hsh->kind == nt && hsh->lmhsh1 == 0 && hsh->lmhsh2 == 0) { |
| 246 | if (hsh->done > 0) { |
| 247 | item(row, 1)->setText("Yes"); |
| 248 | sprintf(tmp, "%d s", hsh->time); |
| 249 | item(row,2)->setText(tmp); |
| 250 | item(row,3)->setText(hsh->table); |
| 251 | sprintf(tmp, "%d", hsh->length); |
| 252 | item(row,4)->setText(tmp); |
| 253 | item(row,5)->setText(category_string(hsh->category)); |
| 254 | } else { |
| 255 | item(row, 1)->setText("No"); |
| 256 | item(row,2)->setText(""); |
| 257 | item(row,3)->setText(""); |
| 258 | item(row,4)->setText(""); |
| 259 | item(row,5)->setText(""); |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | //--------------------------------------------------------------------------- |
| 265 | bool HashModel::removeRow(int row) { |
| 266 | QStandardItem *root = item(row, 0); |
| 267 | int id = root->data(Qt::UserRole).toInt(); |
| 268 | |
| 269 | itemFromId.remove(id); |
| 270 | |
| 271 | return QStandardItemModel::removeRow(row); |
| 272 | } |
| 273 | //--------------------------------------------------------------------------- |
| 274 | void HashModel::setUnameVisible(bool x) { |
| 275 | unameVisible = x; |
| 276 | } |
| 277 | |
| 278 | //--------------------------------------------------------------------------- |
| 279 | void HashModel::setAuditMode(bool x) { |
| 280 | auditMode = x; |
| 281 | |
| 282 | for (int i=0; i<rowCount(); ++i) |
| 283 | for (int j=0; j<columnCount(); ++j) |
| 284 | item(i, j)->setText(""); |
| 285 | |
| 286 | |
| 287 | if (auditMode) { |
| 288 | setHorizontalHeaderItem(0, new QStandardItem("ID")); |
| 289 | setHorizontalHeaderItem(1, new QStandardItem("Cracked")); |
| 290 | setHorizontalHeaderItem(2, new QStandardItem("Time")); |
| 291 | setHorizontalHeaderItem(3, new QStandardItem("Table")); |
| 292 | setHorizontalHeaderItem(4, new QStandardItem("Length")); |
| 293 | setHorizontalHeaderItem(5, new QStandardItem("Category")); |
| 294 | } else { |
| 295 | setHorizontalHeaderItem(0, new QStandardItem("User")); |
| 296 | setHorizontalHeaderItem(1, new QStandardItem("LM Hash")); |
| 297 | setHorizontalHeaderItem(2, new QStandardItem("NT Hash")); |
| 298 | setHorizontalHeaderItem(3, new QStandardItem("LM Pwd 1")); |
| 299 | setHorizontalHeaderItem(4, new QStandardItem("LM Pwd 2")); |
| 300 | setHorizontalHeaderItem(5, new QStandardItem("NT Pwd")); |
| 301 | } |
| 302 | } |