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?

10
  • Use a text editor?
    – forest
    Commented Feb 25, 2019 at 23:07
  • @forest, No tty or pts, so, not possible. Commented Feb 25, 2019 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
    Commented Feb 26, 2019 at 1:32
  • Can't you just use tee to both create and write to a new file without need for any special characters?
    – jonroethke
    Commented Feb 26, 2019 at 1: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
    Commented Feb 26, 2019 at 1:52

3 Answers 3

1

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

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 , , ...

2
  • xxd accepts infile outfile (but needs -r as is). Maybe there's a similar tool that does the opposite.
    – domen
    Commented Apr 2, 2019 at 14:24
  • uudecode will generate file, but first line must contain: begin-base64 644 file.txt so there is one - and always the . of extension. Commented Apr 2, 2019 at 14:29
-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.

1
  • 1
    As I said, it needs to have an extension and write content. Not blank :( Commented Feb 26, 2019 at 5:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .