7

So, I've got a challenge and it's as follows.

You can access a normal shell(sh) on clean RHEL 6 installation. Write arbitrary content to file.txt, but without the following characters.

# & \ + - % @ = : ; , . ' " ^ ` ~ _ | ! / ? * $ # < > [ ] { } ( )

I can use like touch file or rm file but touch file.txt or echo content > file.txt is not allowed due to . and >.

Is this even possible?

  • Use a text editor? – forest Feb 25 '19 at 23:07
  • @forest, No `tty` or `pts`, so, not possible. – rotatorexperiment Feb 25 '19 at 23:38
  • The file "file.txt" already exists and you just have to write to it? or you have to create it and write to it? – hft Feb 26 '19 at 01:32
  • Can't you just use `tee` to both create and write to a new file without need for any special characters? – jonroethke Feb 26 '19 at 01:34
  • Are you not allowed to use the non-alphanumeric keys, or can your commands not contain the characters? `tee` works fine for writing to a file if you can supply the input at the terminal yourself (some editors might work too, though you;ll have a hard time in `vi` without a `:` key), but you're going to have a hard time specifying the file name. – CBHacking Feb 26 '19 at 01:52
  • @CBHacking See OP's first comment. – forest Feb 26 '19 at 02:16
  • Encode the shell script for writing to the file as hexadecimal and execute the result of decoding it, if you can find a way to do that? – Natanael Feb 26 '19 at 02:41
  • @hft Create and write. Since `.` is limited `touch file.txt` can't work. – rotatorexperiment Feb 26 '19 at 02:58
  • @Natanael Can you provide an example for that? Whether it works or not. – rotatorexperiment Feb 26 '19 at 03:00
  • Something like eval or exec to parse decoded hexadecimal as script. Maybe you could even import special characters via getopts from the command line. Perhaps even use the read command to prompt the user to feed in a command and evaluate that as script! – Natanael Feb 26 '19 at 12:59

3 Answers3

1

This is quite simple: check for python, perl or any interpreted language availability, then launch the interpreter and just code it !

binarym
  • 744
  • 4
  • 8
1

First having a look on permited chars:

00 E ''         10 E $'\020'    20 E \     46 - F     56 - V     6C - l      
01 E $'\001'    11 E $'\021'    30 - 0     47 - G     57 - W     6D - m      
02 E $'\002'    12 E $'\022'    31 - 1     48 - H     58 - X     6E - n      
03 E $'\003'    13 E $'\023'    32 - 2     49 - I     59 - Y     6F - o      
04 E $'\004'    14 E $'\024'    33 - 3     4A - J     5A - Z     70 - p      
05 E $'\005'    15 E $'\025'    34 - 4     4B - K     61 - a     71 - q      
06 E $'\006'    16 E $'\026'    35 - 5     4C - L     62 - b     72 - r      
07 E $'\a'      17 E $'\027'    36 - 6     4D - M     63 - c     73 - s      
08 E $'\b'      18 E $'\030'    37 - 7     4E - N     64 - d     74 - t      
09 E $'\t'      19 E $'\031'    38 - 8     4F - O     65 - e     75 - u      
0A E $'\n'      1A E $'\032'    39 - 9     50 - P     66 - f     76 - v      
0B E $'\v'      1B E $'\E'      41 - A     51 - Q     67 - g     77 - w      
0C E $'\f'      1C E $'\034'    42 - B     52 - R     68 - h     78 - x      
0D E $'\r'      1D E $'\035'    43 - C     53 - S     69 - i     79 - y      
0E E $'\016'    1E E $'\036'    44 - D     54 - T     6A - j     7A - z      
0F E $'\017'    1F E $'\037'    45 - E     55 - U     6B - k     7F E $'\177'

... Hmmm this is short!

Then

  • So using variables are not possible, do require a lot of signs, even , without : and =, we're short...
  • using tar and cpio will require - on command line,
  • using uudecode will require first data line to contain - and .
  • same with munpack with a lot of : and some ="--",
  • dd, tee and so on will require dot for extension.... ( Maybe this: tee file܂txt (Note the dot ܂ is UTF-8 &#1794;, not a real dot .), then Hello world and Ctrl+d, but no comment)
  • If possible using an editor who will automatically add .txt extension

No.

From there You have to browse all your FS to find some alternative way or language, like , , ...

-1

This may be a moot point if your challenge rules explicitly say you need a .txt in the file name but..

As this is a Linux distro I don't believe the extension should hold so much significance as the file will still be considered an ASCII text file provided that the first two bytes of the file do not combine to create a shebang or are other magic characters that would otherwise alter the interpretation of the file. See this thread for further explanation.

You should be fine to use tee to create file, write all text to it without issue and then check that it is still a text file by running file file.

jonroethke
  • 1,006
  • 2
  • 7
  • 21