开发者

Borrowing javascript code from one page to inject in another

Alright, let me preface this by saying that I have little programming experience, so I apologize if my explanation belies some serious ignorance. I've always wanted to learn certain tricks but I can never find any tutorials.

Here's the deal:

There's a website that gives you various science questions and grades the input. For each question, there is a button called "Practice Other Versions" that produces a pop-up box with a new, similar version of the problem. This new version also has a button called "Show Answer", which, obviously, shows the solutions.

I used FireBug to find the code of the Show Answer button:

<input type="submit" onclick="key('0','1')" style="border: 1px solid rgb(51, 102, 153); margin-left: 1%;" value="Show Answer" name="Key">

I looked at the "DOM" tab of FireBug to look at the internal code of the key function:

function key(pos, showAnsFlag) {
    setYpos();
    if (showAnsFlag == 1) {
        document.forms[0].showAnswer.value = 1;
        document.forms[0].hideAnswer.value = 0;
    } else {
        document.forms[0].hideAnswer.value = 1;
        document.forms[0].showAnswer.value = 0;
    }
    document.forms[0].pos.value = "";
    document.forms[0].keypos.value = pos;
    document.forms[0].randpos.value = "";
    document.forms[0].solpos.value = "";
    document.forms[0].subaction.value = "key";
}

I also looked at the Net tab of Firebug to discover the POST parameters after I click "Show Solutions":

Key Show Answer
RC_821796_0_0_821813 mc  //[These are the names of the problems]
RC_821796_0_0_开发者_运维问答821813 1
RC_821796_0_1_821813 mc
RC_821796_0_1_821813 0
UserPass //[ERASED, because I'm not sure if it can be used maliciously]
feedback0 rmh
hideAnswer 0
hideSolution 
keypos 0
pos 
randpos 
showAnswer 1
showSolution 
solpos 
struct CuDMAcAACEAuEuEaANErASAJANBPBjDABkCiAaAxAEEfAjCgAvAjDjDQCTDTCbBjAUBtDXDXBqEXAFAjEPAVEMESvVBVzUCcEwALAMCSBQDewWDTAPBUEBCeArESCmDWAfErAXETBFEoBDCEDxBODlCbAeEnCNEKDmDgBHAJESEKATDmAoEFAdCUALCiCLBXCcDFATAcDRDoCwERuUBTDKEkBKESCXATAbDRAwBYEFAeDREWDBCdCeElBJCPCSDtAeABBxDwDDByEPAwEVAtAoDADWCkCCBBAwDNCyEECEAlCeACDCAPCmAsDM
subaction key
ypos 196

Alright, so all that's on the page when I "practice another version." My idea is that I want to call the "key" function (or at least a function that acts exactly like it), when I'm on the normal page, not the "Show Another Version" page. The problem is, when I check the DOM of the normal page, it doesn't even have a key function that is accessible.

Is there any way to inject javascript in the page to force a call to the key function? Optimally, it would be interesting to have a bookmarklet that looped through all of the Questions, calling the key function, and revealing the answers.

Given my paucity of knowledge, I didn't know what to try. I tried simple things like this (in the address bar)

  javascript:document.forms[0].showAnswer.value = 1;

And I know it did something, because when I type

  javascript:alert(document.forms[0].showAnswer.value);

It prompts "1", but I'm just not sure what exactly it's doing, or what else I have to do.

Edit

Let me try to clarify-- I don't own the site, so I'm trying to do some client-side javascript work to manipulate the site into doing what I want (mind you, I'm not even sure this is possible).

On one portion of the site, in a page called "practice.tpl" it allows me to press a button called "Show Answer" (the button calls the aforementioned key function and reveals the solution).

However, on another page, the button and the function do not exist. So I was wondering if I could somehow borrow the key function in the practice.tpl page, and inject it into another page.

Edit 2

This is the source code for the two pages:

Main page (the one where I'm trying to inject code) http://pastebin.com/r7KVMU1N

"Extra Problems" page (the one where the key function is) http://pastebin.com/D8Nc6fbk


On further inspection, this may not be possible, the key values seem to be locked into those struct parameters that the website passes everywhere.

Still, you can try this feasibility test. Firefox with Firebug is required.

  1. Log into a homework section.

  2. Right-click on the whitespace just to the left of the gray question border.

  3. A question-div, like <div id="question3" class="waQBox container"> should be selected. If not, select the nearest one in the HTML tab of Firebug.

  4. Press the Edit button.

  5. Copy and paste all of that code into any text editor with a search function.

  6. Search for "Submit New Answers To".

  7. The found line should contain text like: return submit_this('{BIG HONKING STRING}',true.
    Copy the value of the BIG HONKING STRING, you'll need it in a moment.

  8. Search for UserPass=. Copy the value between the = and the '.

  9. Go back to Firebug; scroll to the bottom of the edit box; and paste in the code, below, just above the third-from-last </div>.

  10. In the newly pasted block, replace the struct input's value with the BIG HONKING STRING from step 7.

  11. In the newly pasted block, replace the UserPass input's value with the string from step 8.

  12. Press the Edit button (edits are complete).

  13. Now, on the page, press the new Show Answer button.

  14. What happens? How the site responds determines whether a GM script is possible.

.

 <form enctype="x-www-form-urlencoded" action="/v4cgi/student/practice.tpl" name="practice" id="practice" method="post">
    <!-- ***** Javascript REQUIRED to copy current UserPass value.
    -->
    <input type="hidden" value="ceeb69f9b47e5660110d5ab7e27ba168" id="UserPass" name="UserPass">

    <input id="struct" name="struct" type="hidden" value="AYCJDoEaCWEbEVErBsBKAbBeDJEEDUBYDEDcDrEhCCBXAkEgBoExDGCDCxBODKBAAWAhAtDIAgCOAQAHACClAnCiCHCMBbEECLBICgBVALCHEhzUCxAxCrzZBPEHEiBSASDfCRCKCFBxDKCCBKCNvVCWBSBbAIAlDVCnBEEkAkBlBuCAEKCLDMDpAHBqCsCcEdAlBiDfCjErAUBTDmEoDqAcEVCfAyBPEJAeABBSEoEpDdEEwWDjCiCNAaESABCdEkDABKDoEuCvAOCRCLCFDfDeClBmAdAuAhELDeEoEnCNBoCOBgAFBfAr">
    <input type="hidden" value="key"    id="subaction" name="subaction">
    <input type="hidden" value=""       id="pos" name="pos">
    <input type="hidden" value="0"      id="keypos" name="keypos">
    <input type="hidden" value=""       id="randpos" name="randpos">
    <input type="hidden" value=""       id="solpos" name="solpos">
    <!-- ***** Javascript desired.  "7" to window.pageYOffset
    -->
    <input type="hidden" value="7"      id="ypos" name="ypos">
    <input type="hidden" value="1"      id="showAnswer" name="showAnswer">
    <input type="hidden" value="0"      id="hideAnswer" name="hideAnswer">
    <input type="hidden" value="" id="showSolution" name="showSolution">
    <input type="hidden" value="" id="hideSolution" name="hideSolution">
    <input type="hidden" value="r"      id="feedback0" name="feedback0">

    <!-- ***** If this value is required, then the whole process may be very difficult.
        But it's probably not.
    -->
    <input type="text" id="RN_821703_0_0_821745" name="RN_821703_0_0_821745" value="">

    <input type="submit" value="Show Answer" name="Key">
</form>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜