blob: 7a4107bf93b4ece244632bfd780475cad8c5464c [file] [log] [blame]
Mark Mentovai4febb342022-09-07 10:34:05 -04001// Copyright 2010 Google LLC
nealsid8d2c5182010-08-24 14:28:10 +00002//
3// Redistribution and use in source and binary forms, with or without
4// modification, are permitted provided that the following conditions are
5// met:
6//
7// * Redistributions of source code must retain the above copyright
8// notice, this list of conditions and the following disclaimer.
9// * Redistributions in binary form must reproduce the above
10// copyright notice, this list of conditions and the following disclaimer
11// in the documentation and/or other materials provided with the
12// distribution.
Mark Mentovai4febb342022-09-07 10:34:05 -040013// * Neither the name of Google LLC nor the names of its
nealsid8d2c5182010-08-24 14:28:10 +000014// contributors may be used to endorse or promote products derived from
15// this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29// exploitability_engine.cc: Generic exploitability engine.
30//
31// See exploitable_engine.h for documentation.
32//
33// Author: Cris Neckar
34
35
36#include <cassert>
37
ted.mielczarek@gmail.com63c5d982013-01-17 15:53:56 +000038#include "common/scoped_ptr.h"
nealsid8d2c5182010-08-24 14:28:10 +000039#include "google_breakpad/processor/exploitability.h"
40#include "google_breakpad/processor/minidump.h"
41#include "google_breakpad/processor/process_state.h"
mattdr.breakpad@gmail.com502f2322013-10-29 20:03:39 +000042#include "processor/exploitability_linux.h"
cdn@chromium.orgcec12872010-09-22 02:37:19 +000043#include "processor/exploitability_win.h"
nealsid8d2c5182010-08-24 14:28:10 +000044#include "processor/logging.h"
nealsid8d2c5182010-08-24 14:28:10 +000045
46namespace google_breakpad {
47
48Exploitability::Exploitability(Minidump *dump,
49 ProcessState *process_state)
50 : dump_(dump),
51 process_state_(process_state) {}
52
53ExploitabilityRating Exploitability::CheckExploitability() {
54 return CheckPlatformExploitability();
55}
56
57Exploitability *Exploitability::ExploitabilityForPlatform(
58 Minidump *dump,
59 ProcessState *process_state) {
Liu.andrew.x@gmail.comf0735402015-08-21 16:22:19 +000060 return ExploitabilityForPlatform(dump, process_state, false);
61}
62
63Exploitability *Exploitability::ExploitabilityForPlatform(
64 Minidump *dump,
65 ProcessState *process_state,
66 bool enable_objdump) {
nealsid8d2c5182010-08-24 14:28:10 +000067 Exploitability *platform_exploitability = NULL;
68 MinidumpSystemInfo *minidump_system_info = dump->GetSystemInfo();
69 if (!minidump_system_info)
70 return NULL;
71
72 const MDRawSystemInfo *raw_system_info =
73 minidump_system_info->system_info();
74 if (!raw_system_info)
75 return NULL;
76
77 switch (raw_system_info->platform_id) {
78 case MD_OS_WIN32_NT:
cdn@chromium.orgcec12872010-09-22 02:37:19 +000079 case MD_OS_WIN32_WINDOWS: {
mattdr.breakpad@gmail.com502f2322013-10-29 20:03:39 +000080 platform_exploitability = new ExploitabilityWin(dump, process_state);
81 break;
82 }
83 case MD_OS_LINUX: {
Liu.andrew.x@gmail.comf0735402015-08-21 16:22:19 +000084 platform_exploitability = new ExploitabilityLinux(dump,
85 process_state,
86 enable_objdump);
cdn@chromium.orgcec12872010-09-22 02:37:19 +000087 break;
88 }
nealsid8d2c5182010-08-24 14:28:10 +000089 case MD_OS_MAC_OS_X:
qsr@chromium.orgb9583792011-10-11 14:17:02 +000090 case MD_OS_IOS:
cdn@chromium.orgcec12872010-09-22 02:37:19 +000091 case MD_OS_UNIX:
nealsid8d2c5182010-08-24 14:28:10 +000092 case MD_OS_SOLARIS:
digit@chromium.org8d967072012-07-04 11:56:26 +000093 case MD_OS_ANDROID:
thestig@chromium.org0bdc7142013-04-25 20:36:31 +000094 case MD_OS_PS3:
Ivan Penkov4a6d7c72019-07-11 18:34:48 -070095 case MD_OS_FUCHSIA:
nealsid8d2c5182010-08-24 14:28:10 +000096 default: {
97 platform_exploitability = NULL;
98 break;
99 }
100 }
101
102 BPLOG_IF(ERROR, !platform_exploitability) <<
103 "No Exploitability module for platform: " <<
104 process_state->system_info()->os;
105 return platform_exploitability;
106}
107
ted.mielczarek@gmail.comaeffe102013-03-06 14:04:42 +0000108bool Exploitability::AddressIsAscii(uint64_t address) {
cdn@chromium.org8b2e6862010-10-01 23:25:48 +0000109 for (int i = 0; i < 8; i++) {
ted.mielczarek@gmail.comaeffe102013-03-06 14:04:42 +0000110 uint8_t byte = (address >> (8*i)) & 0xff;
cdn@chromium.org8b2e6862010-10-01 23:25:48 +0000111 if ((byte >= ' ' && byte <= '~') || byte == 0)
112 continue;
113 return false;
114 }
115 return true;
116}
117
nealsid8d2c5182010-08-24 14:28:10 +0000118} // namespace google_breakpad
119