c%2B%2B - Dave's Blog

Search
My timeline on Mastodon

Retweet of blubbfiction

2015 Dec 12, 6:22
Replay attacks against HTTPS - http://blog.valverde.me/2015/12/07/bad-life-advice/#.Vm2ATTAxldZ …
PermalinkComments

Retweet of lyndonhood

2015 Aug 19, 4:07
So I wondered what would happen if you replaced every adjective in a Lovecraft story with 'spooky'. pic.twitter.com/VjlQAV7tap
PermalinkComments

Retweet of stshank

2015 Apr 13, 9:23
UIforETW: New open-source tool from Google to make it easier to use Microsoft Event Tracing for Windows (aka xperf): http://bit.ly/1Df9jzt 
PermalinkComments

Retweet of stshank

2015 Mar 14, 10:42
Mobile developers flocked to iOS and Android, but @dontcallmeDOM says the Web is fighting back with new standards. http://cnet.co/1MDx2vh 
PermalinkComments

Retweet of bropanski

2015 Mar 13, 4:44
pic.twitter.com/1yc32oPRlE
PermalinkComments

Retweet of TheOnion

2015 Mar 11, 9:58
"We’ll be able to systematically deceive investors in the time it takes to press a button." http://onion.com/18fgr3J  pic.twitter.com/8E8QiIk5m6
PermalinkComments

Retweet of lessig

2015 Mar 11, 8:47
Join the Mayday v2 Thunderclap? @ThunderclapIt // @MAYDAYUS http://thndr.it/1Eyi2Ow 
PermalinkComments

Retweet of TheOnion

2015 Mar 9, 12:11
How Cable Companies Plan To Fight Cord Cutting http://onion.com/1aXT9RD  pic.twitter.com/1e2qYRFCMN
PermalinkComments

Retweet of TheOnion

2015 Feb 8, 9:00
New Premium Uber Service Lets Users Commandeer Any Car http://onion.com/1DYe4vS  pic.twitter.com/6tLHOHz48t
PermalinkComments

Cloud Share - New App

2014 May 23, 4:06

I've put a new app on the Windows Store: Cloud Share. It connects the web to your Windows 8 share charm.

I did the development on GitHub and quite enjoyed myself. I wasn't sure I liked the game-ification of development in GitHub's dashboard showing you your longest development streak in days. However I realized that it encourages me to do work on my personal project and anything that aids in holding my attention on and helping me finish these projects is a good thing.

PermalinkCommentsdevelopment github javascript JS technical windows

URI functions in Windows Store Applications

2013 Jul 25, 1:00PermalinkCommentsc# c++ javascript technical uri windows windows-runtime windows-store

MSVC++ 64bit Enums

2013 Jul 1, 1:00

If you want to represent a value larger than 32bits in an enum in MSVC++ you can use C++0x style syntax to tell the compiler exactly what kind of integral type to store the enum values. Unfortunately by default an enum is always 32bits, and additionally while you can specify constants larger than 32bits for the enum values, they are silently truncated to 32bits.

For instance the following doesn't compile because Lorem::a and Lorem::b have the same value of '1':


enum Lorem {
a = 0x1,
b = 0x100000001
} val;

switch (val) {
case Lorem::a:
break;
case Lorem::b:
break;
}

Unfortunately it is not an error to have b's constant truncated, and the previous without the switch statement does compile just fine:


enum Lorem {
a = 0x1,
b = 0x100000001
} val;

But you can explicitly specify that the enum should be represented by a 64bit value and get expected compiling behavior with the following:


enum Lorem : UINT64 {
a = 0x1,
b = 0x100000001
} val;

switch (val) {
case Lorem::a:
break;
case Lorem::b:
break;
}
PermalinkComments64bit c++ development enum msvc++ technical

Stripe CTF - XSS, CSRF (Levels 4 & 6)

2012 Sep 10, 4:43

Level 4 and level 6 of the Stripe CTF had solutions around XSS.

Level 4

Code

> Registered Users 

    <%@registered_users.each do |user| %>
    <%last_active = user[:last_active].strftime('%H:%M:%S UTC') %>
    <%if @trusts_me.include?(user[:username]) %>

  • <%= user[:username] %>
    (password: <%= user[:password] %>, last active <%= last_active %>)
  • Issue

    The level 4 web application lets you transfer karma to another user and in doing so you are also forced to expose your password to that user. The main user page displays a list of users who have transfered karma to you along with their password. The password is not HTML encoded so we can inject HTML into that user's browser. For instance, we could create an account with the following HTML as the password which will result in XSS with that HTML:

    
    
    This HTML runs script that uses jQuery to post to the transfer URI resulting in a transfer of karma from the attacked user to the attacker user, and also the attacked user's password.

    Notes

    Code review red flags in this case included lack of encoding when using user controlled content to create HTML content, storing passwords in plain text in the database, and displaying passwords generally. By design the web app shows users passwords which is a very bad idea.

    Level 6

    Code

    
    

    ...

    def self.safe_insert(table, key_values)
    key_values.each do |key, value|
    # Just in case people try to exfiltrate
    # level07-password-holder's password
    if value.kind_of?(String) &&
    (value.include?('"') || value.include?("'"))
    raise "Value has unsafe characters"
    end
    end

    conn[table].insert(key_values)
    end

    Issue

    This web app does a much better job than the level 4 app with HTML injection. They use encoding whenever creating HTML using user controlled data, however they don't use encoding when injecting JSON data into script (see post_data initialization above). This JSON data is the last five most recent messages sent on the app so we get to inject script directly. However, the system also ensures that no strings we write contains single or double quotes so we can't get out of the string in the JSON data directly. As it turns out, HTML lets you jump out of a script block using no matter where you are in script. For instance, in the middle of a value in some JSON data we can jump out of script. But we still want to run script, so we can jump right back in. So the frame so far for the message we're going to post is the following:

    
    
    
    
PermalinkCommentscsrf encoding html internet javascript percent-encoding script security stripe-ctf technical web xss

Fwd: High chair

2012 Feb 13, 12:58

PermalinkComments

Fwd: High chair

2012 Feb 13, 12:58

PermalinkComments

Kevin and Eileen's Photos of Our Wedding - Kevin, Dave and Matthew

2010 Jun 5, 3:54

PermalinkComments

Encode-O-Matic: Guess Encoding

2010 Apr 4, 2:02

I've just updated Encode-O-Matic with a Guess Input Encoding feature. When you start Encode-O-Matic or when you use the 'Guess Input Encoding' menu item from the 'Tools' menu, Encode-O-Matic will try out various combinations of encodings and guess at which set seem to apply to your input. For instance given the following text, Encode-O-Matic will correctly guess that it is percent encoded, base64 encoded, deflate compressed text:

S%2BWqUEhLLMoFUulFpXnZQLogMa%2BkmCuPqxzILk%2FMyeHK4QIA
It should work fairly well for simple things but I did pick 'Guess' for the name of the feature to intentionally lower expectations. It doesn't currently apply to character encodings but that may be something to consider in the future.PermalinkCommentstechnical encodeomatic tool encoding

Eat Pants - Interactive Fiction Sessions from my Server Logs

2009 Jun 29, 4:19

I've looked at my web server logs previously to see if anyone had used my Web Frotz Interpreter and until recently didn't realize that awstats (the web server log report generator) was truncating the query from my URL, so I couldn't tell that anyone was actually using it. But after grepping the logs manually I've pulled out the URLs of visitor's text adventure sessions. If you'll recall, my Web Frotz Interpreter stores the game state in the URL so its easy to see user's game states in the web server logs.

I've put some of the links up on the Web Frotz Interpreter page. Some of the interesting ones:

PermalinkCommentsserver-logs technical zork frotz pants interactive-fiction uri if

URI Addressable Text Adventure Games

2008 Mar 2, 9:18

This post is about creating a server side z-code interpreter that represents game progress in the URI. Try it with the game Lost Pig.

I enjoy working on URIs and have the mug to prove it. Along those lines I've combined thoughts on URIs with interactive fiction. I have a limited amount of experience with Inform which generates Z-Code so I'll focus on pieces written in that. Of course we can already have URIs identifying the Z-Code files themselves, but I want URIs to identify my place in a piece of interactive fiction. The proper way to do this would be to give Z-Code its own mimetype and associate with that mimetype the format of a fragment that would contain the save state of user's interactive fiction session. A user would install a browser plugin that would generate URIs containing the appropriate fragment while you play the IF piece and be able to load URIs identifying Z-Code files and load the save state that appears in the fragment.

But all of that would be a lot of work, so I made a server side version that approximates this. On the Web Frotz Interpreter page, enter the URI of a Z-Code file to start a game. Enter your commands into the input text box at the bottom and you get a new URI after every command. For example, here's the beginning of Zork. I'm running a slightly modified version of the Unix version of Frotz. Baf's Guide to the IF Archive has lists of IF games to try out.

There are two issues with this thought, the first being the security issues with running arbitrary z-code and the second is the practical URI length limit of about 2K in IE. From the Z-Code standard and the Frotz source it looks like 'save' and 'restore' are the only commands that could do anything interesting outside of the Z-Code virtual machine. As for the length-limit on URIs I'm not sure that much can be done about that. I'm using a base64 encoded copy of the compressed input stream in the URI now. Switching to the actual save state might be smaller after enough user input.

PermalinkCommentszork frotz interactive-fiction zcode if technical uri fragment

Wp64 Issues

2007 Aug 6, 3:43Miladin told me about the Visual Studio compiler's promising option Wp64 that finds 64bit portability issues when compiling in 32bit. If, for instance, you cast from a (long*) to a (long) you get a W4 warning. However, the #defines are still set for 32bit builds. This means that other parts of the code can make assumptions based on the #defines that are valid on 32bit but generate 64bit errors or warnings.

For instance, in winuser.h the public published Windows header file there's the following:
...
#ifdef _WIN64
...
WINUSERAPI
LONG_PTR
WINAPI
SetWindowLongPtrA(
    __in HWND hWnd,
    __in int nIndex,
    __in LONG_PTR dwNewLong);
...
#else  /* _WIN64 */
...
#define SetWindowLongPtrA   SetWindowLongA
...
#endif /* _WIN64 */
...
In 64bit everything's normal but in 32bit SetWindowLongPtrA is #defined to SetWindowLongA which takes a LONG rather than a LONG_PTR. So take the following code snippet:
...
LONG_PTR inputValue = 0;
LONG_PTR error = SetWindowLongPtrA(hWnd, nIndex, inputValue);
...
This looks fine but generates warnings with the Wp64 flag.

In 64 bit, p is cast to (LONG_PTR) and that's great because we're actually calling SetWindowLongPtrA which takes a LONG_PTR. In 32 bit, p is cast to (LONG_PTR) which is then implicitly cast to (LONG) because we're actually calling SetWindowLongA. LONG and LONG_PTR are the same size in 32bit which is fine but if you turn on the Wp64 flag there's a W4 warning because of the implicit cast from a larger size to a smaller size if you were to compile for 64bit. So even though doing a 32bit or 64bit compile would have worked just fine, if you turn on the Wp64 flag for 32bit you'd get an error here.

It looks like I'm the most recent in a list of people to notice this issue. Well I investigated this so... I'm blogging about it too!PermalinkCommentswp64 technical 64bit compiler c++ visual-studio setwindowlongptra
Older Entries Creative Commons License Some rights reserved.