mIRC Home    About    Download    Register    News    Help

Print Thread
#243473 23/11/13 03:59 PM
Joined: Nov 2013
Posts: 49
L
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Nov 2013
Posts: 49
Is there need for protecting yourself against scripting input?

If so, how does one check a string for '$'?

Thanks.

Joined: Jan 2004
Posts: 1,359
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,359
Just be careful not to evaluate the text. That means always using the n switch with $read. Timers also evaluate text, so with timers use the following alias:

Code:
alias safe return $!decode( $encode($1,m) ,m)


Encode any input as $safe($time) to prevent it from being evaluated. I can't think of other cases, but there might be a couple.

Last edited by Loki12583; 23/11/13 07:41 PM.
Joined: Nov 2013
Posts: 49
L
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Nov 2013
Posts: 49
You're going to have to explain that alias a bit further into details for me mate.

I've been working a bit with
alias {

}
and am getting around to understanding it - now you're throwing "safe return $!decode" in front of it, kind of colors me confused.

I understand that evaluating a text means considering it as 'code'. Not sure how the alias relates to it though.

Thanks!

Joined: Jan 2004
Posts: 1,359
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,359
'alias' is the keyword to define an alias, it can be a block of code as you've said or it can be a single line. 'safe' is the name of the alias. 'return' is a command which returns a value when you call the alias. If I had an alias "alias pi return 3.14", then $pi would be replaced by 3.14 whenever it was used.

The usage of $safe is only necessary because of the behavior of timers. Timers will evaluate identifiers inside of them. What the safe alias does is encapsulate the text in $decode so that $decode is evaluated instead of the original contents.

You can see the behavior of safe in the following aliases. First, I store the text "$time" inside of $1-. You can see that in /a when the timer ends $time is actually evaluated and the current time is printed. In /b when the timer ends you see the literal text "$time" is printed.

Code:
alias a {
  tokenize 32 $!time
  echo -ag input is: $1-
  write -c test.txt $1-
  echo -ag result of $!read: $read(test.txt,1)
  .timer 1 0 echo -ag result of timer: $1-
  .remove test.txt
}

alias b {
  tokenize 32 $!time
  echo -ag input is: $1-
  write -c test.txt $1-
  echo -ag result of $!read: $read(test.txt,n,1)
  .timer 1 0 echo -ag result of timer: $safe($1-)
  .remove test.txt
}

Joined: Jul 2006
Posts: 4,163
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,163
More on eval injection here http://www.zigwap.com/mirc/eval_injection


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Nov 2013
Posts: 49
L
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Nov 2013
Posts: 49
Brilliant Loki. You should teach, that was very basic and understandable.

Appreciated.


Link Copied to Clipboard