Skip to content

Commit 74c66d9

Browse files
committed
mix content issue solved
1 parent 64cec6f commit 74c66d9

File tree

5 files changed

+324
-204
lines changed

5 files changed

+324
-204
lines changed
Lines changed: 68 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,69 @@
1-
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
2-
//alert("background js");
3-
if (changeInfo.status == 'complete') {
4-
chrome.tabs.getSelected(null, function (tab) {
5-
chrome.tabs.sendRequest(0, {
6-
method: "getText"
7-
}, function (response) {
8-
if (response.method == "getText") {
9-
alltext = response.data;
10-
}
11-
});
12-
});
1+
chrome.browserAction.onClicked.addListener(function (tab) {
2+
chrome.tabs.executeScript({
3+
code: 'document.body.style.backgroundColor="red"'
4+
});
5+
chrome.tabs.executeScript(null, { file: "page_analyzer.js" });
6+
// chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
7+
// chrome.tabs.sendMessage(tabs[0].id, {greeting: "hello"}, function(response) {
8+
// console.log(response.farewell);
9+
// });
10+
// });
11+
12+
});
13+
14+
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
15+
console.log(sender.tab ?
16+
"from a content script:" + sender.tab.url :
17+
"from the extension");
18+
console.log(request);
19+
initiateProcess(request)
20+
// if (request.greeting == "hello")
21+
// sendResponse({farewell: "goodbye"});
22+
});
23+
24+
function initiateProcess(obj) {
25+
var cookies = obj.cookies;
26+
var currentUrl = obj.currentUrl;
27+
var scripts = obj.scripts;
28+
for (var i = 0; i < scripts.length; i++) {
29+
loadDoc(i, scripts[i].src, scripts[i].content);
1330
}
14-
})
31+
postCookies(cookies, currentUrl);
32+
33+
}
34+
35+
function postCookies(cookies, currentUrl) {
36+
var xhttp = new XMLHttpRequest();
37+
xhttp.onreadystatechange = function () {
38+
if (this.readyState === 4 && this.status === 200) {
39+
getScriptContent();
40+
}
41+
};
42+
xhttp.open("POST", "http://localhost:55168/home/PostCookies", true);
43+
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
44+
xhttp.send("cookies=" + cookies + "&url=" + currentUrl);
45+
}
46+
47+
48+
function loadDoc(scriptNumber, src, content) {
49+
var xhttp = new XMLHttpRequest();
50+
xhttp.onreadystatechange = function () {
51+
if (this.readyState === 4 && this.status === 200) {
52+
}
53+
};
54+
xhttp.open("POST", "http://localhost:55168/home/PostScript", true);
55+
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
56+
xhttp.send("Number=" + scriptNumber + "&Source=" + src + "&Content=" + content);
57+
}
58+
59+
function getScriptContent() {
60+
var xhttp = new XMLHttpRequest();
61+
xhttp.onreadystatechange = function () {
62+
if (this.readyState === 4 && this.status === 200) {
63+
}
64+
};
65+
xhttp.open("GET", "http://localhost:55168/home/GetScriptContent", true);
66+
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
67+
xhttp.send();
68+
}
69+
Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,46 @@
1+
//{
2+
// "manifest_version": 2,
3+
4+
// "name": "Getting started example",
5+
// "description": "This extension allows the user to change the background color of the current page.",
6+
// "version": "1.0",
7+
8+
// "browser_action": {
9+
// "default_icon": "icon.png",
10+
// "default_popup": "popup.html"
11+
// },
12+
// "permissions": [
13+
// "activeTab",
14+
// "storage"
15+
// ]
16+
//}
17+
18+
119
{
220
"manifest_version": 2,
21+
"name": "JS Finder",
22+
"description": "Make the current page red",
23+
"version": "2.0",
324

4-
"name": "XSSI Check",
5-
"description": "This extension will analyze a page and find out if it is trying to be accessed by xssi.",
6-
"version": "1.0",
7-
8-
"permissions": [
9-
"webNavigation",
10-
"*://*/*"
11-
],
1225
"background": {
13-
"scripts": ["jquery-3.2.1.min.js","getPageSource.js","background.js"]
26+
"scripts": [ "background.js" ],
27+
"persistent": false
1428
},
1529
"browser_action": {
16-
"default_icon": "img/icon.png",
17-
"default_popup": "popup.html"
30+
"default_icon": "/img/icon.png",
31+
"default_title": "Read the js of current page"
32+
//"default_popup": "popup.html"
1833
},
19-
"content_scripts": [
20-
{
21-
"matches": ["*://*/*"],
22-
"js": ["jquery-3.2.1.min.js", "page_analyzer.js"],
23-
"run_at": "document_end"
24-
}
34+
"permissions": [
35+
"*://*/*",
36+
"activeTab"
2537
]
38+
//,
39+
//"content_scripts": [
40+
//{
41+
//"matches": [ "*://*/*" ]
42+
//,
43+
//"js": [ "page_analyzer.js" ]
44+
//}
45+
//]
2646
}
Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,36 @@
1-
//document.body.innerHTML = document.body.innerHTML.replace(new RegExp("Gmail", "g"), "nobody");
1+
chrome.runtime.onMessage.addListener(
2+
function (request, sender, sendResponse) {
3+
console.log(sender.tab ?
4+
"from a content script:" + sender.tab.url :
5+
"from the extension");
6+
if (request.greeting == "hello")
7+
sendResponse({ farewell: "goodbye" });
8+
});
29

3-
window.onload = function () {
10+
// chrome.runtime.sendMessage({greeting: "hello"}, function(response) {
11+
// console.log(response.farewell);
12+
// });
13+
14+
findScripts((obj) => {
15+
console.log(obj);
16+
chrome.runtime.sendMessage(obj, function (response) {
17+
//console.log(response.farewell);
18+
});
19+
});
20+
21+
function findScripts(callback) {
22+
var scriptList = [];
423
var cookies = document.cookie;
524
var currenturl = window.location.href;
625
var scripts = document.getElementsByTagName("script");
7-
for (var i = 0; i < scripts.length; i++) {
26+
for (var i = 0; i < scripts.length; i++) {
827
if (scripts[i].src) {
9-
console.log(i, scripts[i].src);
10-
11-
loadDoc(i, scripts[i].src, "");
12-
}
13-
else {
14-
console.log(i, scripts[i]);
15-
loadDoc(i, window.location.href, scripts[i].innerHTML);
28+
scriptList.push({ index: i, src: scripts[i].src, content: "" });
1629
}
30+
//else {
31+
//scriptList.push({index:i, src: window.location.href, content:scripts[i].innerHTML});
32+
//}
1733
}
18-
postCookies(cookies, currenturl);
19-
//getScriptContent();
20-
//alert(scripts.length);
21-
}
22-
23-
function postCookies(cookies, currenturl) {
24-
var xhttp = new XMLHttpRequest();
25-
xhttp.onreadystatechange = function () {
26-
if (this.readyState === 4 && this.status === 200) {
27-
getScriptContent();
28-
}
29-
};
30-
xhttp.open("POST", "http://localhost:55168/home/PostCookies", true);
31-
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
32-
xhttp.send("cookies="+cookies+"&url="+ currenturl);
33-
}
34+
callback({ currentUrl: currenturl, cookies: cookies, scripts: scriptList });
3435

35-
36-
function loadDoc(scriptNumber, src, content) {
37-
var xhttp = new XMLHttpRequest();
38-
xhttp.onreadystatechange = function () {
39-
if (this.readyState === 4 && this.status === 200) {
40-
}
41-
};
42-
xhttp.open("POST", "http://localhost:55168/home/PostScript", true);
43-
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
44-
xhttp.send("Number=" + scriptNumber + "&Source=" + src + "&Content=" + content);
45-
}
46-
47-
48-
function getScriptContent() {
49-
var xhttp = new XMLHttpRequest();
50-
xhttp.onreadystatechange = function () {
51-
if (this.readyState === 4 && this.status === 200) {
52-
}
53-
};
54-
xhttp.open("GET", "http://localhost:55168/home/GetScriptContent", true);
55-
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
56-
xhttp.send();
5736
}

xssi check/jsFinder/app/popup.html

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,49 @@
11
<!doctype html>
2+
<!--
3+
This page is shown when the extension button is clicked, because the
4+
"browser_action" field in manifest.json contains the "default_popup" key with
5+
value "popup.html".
6+
-->
27
<html>
38
<head>
4-
<title>XSSI Check</title>
5-
<script src="popup.js"></script>
9+
<title>Getting Started Extension's Popup</title>
10+
<style type="text/css">
11+
body {
12+
margin: 10px;
13+
white-space: nowrap;
14+
}
15+
16+
h1 {
17+
font-size: 15px;
18+
}
19+
20+
#container {
21+
align-items: center;
22+
display: flex;
23+
justify-content: space-between;
24+
}
25+
</style>
26+
<!--
27+
- JavaScript and HTML must be in separate files: see our Content Security
28+
- Policy documentation[1] for details and explanation.
29+
-
30+
- [1]: https://developer.chrome.com/extensions/contentSecurityPolicy
31+
-->
632
<script src="jquery-3.2.1.min.js"></script>
33+
<script src="popup.js"></script>
734
</head>
835
<body>
9-
<h1>Checking now..</h1>
10-
<button id="checkPage">Check</button>
36+
<h1>Background Color Changer</h1>
37+
<div id="container">
38+
<span>Choose a color</span>
39+
<!--<select id="dropdown">
40+
<option selected disabled hidden value=''></option>
41+
<option value="white">White</option>
42+
<option value="pink">Pink</option>
43+
<option value="green">Green</option>
44+
<option value="yellow">Yellow</option>
45+
</select>-->
46+
<button id="checkPage">Check</button>
47+
</div>
1148
</body>
12-
</html>
49+
</html>

0 commit comments

Comments
 (0)