Bonsoir,
je veux créer un fichier xml nmapResult.xml de la forme suivante:
pour ce faire, j'ai développé ce code<?xmlversion="1.0"encoding="UTF-8"?>
<site>
<Information>
<Ip>192.168.229.128</Ip>
<OS>Running: Microsoft Windows XP</OS
<ports>
<port>80/tcp open http Apache httpd 2.2.21 ((Win32) PHP/5.3.10)</port>
<port>135/tcp open msrpc Microsoft Windows RPC</port>
<port>139/tcp open netbios-ssn</port>
<port>3306/tcp open mysql MySQL</port>
</ports>
<Cms>Aucune utilisation de CMS</Cms>
</information>
</site>
public class createxml {
ça fonctionnait très bien, mais quand j'ai ajouté ces lignes:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229 public static void main(String[] args) { List<String> rs = new ArrayList<>(); String[]cmd = new String[4]; cmd[0] = "nmap"; cmd[1] = "-sS"; cmd[2] = "-O"; cmd[3] = "192.168.1.1/dvwa/login.php"; //cmd[4] = "-oX"; // cmd[5] = "scan.xml"; Runtime r = Runtime.getRuntime(); Process p = null; try { p = r.exec(cmd); } catch (IOException ex) { // Logger.getLogger(ScannerForm.class.getName()).log(Level.SEVERE, null, ex); } BufferedReader bfr = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = ""; final List<String> ports = new ArrayList<String>(); final List<String> oss = new ArrayList<String>(); final List<String> Url = new ArrayList<String>(); String mac = ""; try { while ((line = bfr.readLine()) != null){ if (line.contains("/tcp") || line.contains("/Http")) { ports.add(line); } if (line.contains("MAC")) { mac = line; } if (line.contains("OS")) { oss.add(line); } if (line.contains("myrouter")) { // int l=line.length(); line= line.substring(36,line.length()-1); Url.add(line); } } }catch (IOException ex) { } String script = "/pentest/web/blindelephant/src/blindelephant/BlindElephant.py"; String[]cmd1 = new String[4]; cmd1[0] = "python"; cmd1[1] = script; cmd1[2] = "192.168.1.1/dvwa/login.php"; cmd1[3] = "guess"; Runtime r1 = Runtime.getRuntime(); Process p1 = null; try { p1 = r1.exec(cmd1); } catch (IOException ex) { } BufferedReader bfr1 = new BufferedReader(new InputStreamReader(p1.getInputStream())); //BufferedReader bfr2 = new BufferedReader(bfr1, bfr); String line1 = ""; // String pro = ""; String msg = ""; final List<String> pro = new ArrayList<String>(); try { while ((line1 = bfr1.readLine()) != null){ if (line1.contains("probing")) { msg = "Aucune identification CMS"; pro.add(msg); } } } catch (IOException ex) { } try { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document doc = docBuilder.newDocument(); Element rootElement = doc.createElement("site"); doc.appendChild(rootElement); // Element adresse=doc.createElement("Addresse"); Element information = doc.createElement("information"); if (!Url.isEmpty()) { Element url = doc.createElement("url"); url.appendChild(doc.createTextNode(Url.get(0))); url.appendChild(url); } if (!oss.isEmpty()) { Element os = doc.createElement("os"); os.appendChild(doc.createTextNode(oss.get(0))); information.appendChild(os); } if (!pro.isEmpty()) { Element cms = doc.createElement("cms"); cms.appendChild(doc.createTextNode(msg)); information.appendChild(cms); } Element listOfports = doc.createElement("ports"); Element pr; for (String port : ports) { pr = doc.createElement("port"); pr.appendChild(doc.createTextNode(port)); listOfports.appendChild(pr); } information.appendChild(listOfports); rootElement.appendChild(information); // write the content into xml file TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(new File("nmapResult.xml")); transformer.transform(source, result); } catch (ParserConfigurationException pce) { pce.printStackTrace(); } catch (TransformerException tfe) { tfe.printStackTrace(); } } }
j'obtiens l'erreur suivant:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 if (!pro.isEmpty()) { Element cms = doc.createElement("cms"); cms.appendChild(doc.createTextNode(msg)); information.appendChild(cms); }
Pouvez vous m'aidez SVP??
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 Exception in thread "main" org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted. at com.sun.org.apache.xerces.internal.dom.ParentNode.internalInsertBefore(ParentNode.java:379) at com.sun.org.apache.xerces.internal.dom.ParentNode.internalInsertBefore(ParentNode.java:379) at com.sun.org.apache.xerces.internal.dom.ParentNode.internalInsertBefore(ParentNode.java:379)![]()
Partager