concept method in category security

appears as: method, methods, method, The method, A method, methods
The Art of Network Penetration Testing

This is an excerpt from Manning's book The Art of Network Penetration Testing.

Regardless of the method of remote control, the motivation and key focus throughout this entire phase of an INPT is to gain an initial foothold into our target environment and access as many restricted areas of the network as we can.

Using methods

You’ve just written your first Ruby program, even though it doesn’t do that much, and you haven’t really used much of the Ruby language, so let’s see to it a little bit. First, you’ll wrap the call to the puts “Hello world!” inside its own method and call it that way. A method or function is a little snippet of code that is wrapped inside a block which can then be called multiple times by other sections of code in the same program. Open your hello.rb file again with vim. Switch into Insert mode and then make the following modifications to your code:

#!/usr/bin/env ruby
 
def sayhello()
  puts "Hello World!"
end
 
sayhello()

In case it’s not obvious to you, you defined a method named sayhello() and placed the call to puts “Hello World” inside the method. Then you call the method. If you exit and save, you’ll notice that the program does exactly the same thing as it did before; it’s just using a method call to do it.

API Security in Action

This is an excerpt from Manning's book API Security in Action.

  • A variant of the RPC style known as Remote Method Invocation (RMI) uses object-oriented techniques to allow clients to call methods on remote objects as if they were local. RMI approaches used to be very popular, with technologies such as CORBA and Enterprise Java Beans (EJBs) often used for building large enterprise systems. The complexity of these frameworks has led to a decline in their use.
  • A preflight request occurs when a browser would normally block the request for violating the same-origin policy. The browser makes a HTTP OPTIONS request to the server asking if the request should be allowed. The server can either deny the request or else allow it with restrictions on the allowed headers and methods.

    Figure 5.2 When a script tries to make a cross-origin request that would be blocked by the SOP, the browser now makes a CORS preflight request to the target server to ask if the request should be permitted. If the server agrees, and any conditions it specifies are satisfied, then the browser makes the original request and lets the script see the response. Otherwise, the browser blocks the request.

    The browser first makes an HTTP OPTIONS request to the target server. It includes the origin of the script making the request as the value of the Origin header, along with some headers indicating the HTTP method of the method that was requested (Access-Control-Request-Method header) and any non-standard headers that were in the original request (Access-Control-Request-Headers).

    Finally, you need to schedule a periodic task to call the method to delete the expired tokens. There are many ways you could do this in production. Some frameworks include a scheduler for these kinds of tasks, or you could expose the method as a REST endpoint and call it periodically from an external job. If you do this, remember to apply rate-limiting to that endpoint or require authentication (or a special permission) before it can be called, as in the following example:

    before("/expired_tokens", userController::requireAuthentication);
    delete("/expired_tokens", (request, response) -> {
        databaseTokenStore.deleteExpiredTokens();
        return new JSONObject();
    });

    For now, you can use a simple Java scheduled executor service to periodically call the method. Open DatabaseTokenStore.java again and add the following lines to the constructor:

    Secure by Design

    This is an excerpt from Manning's book Secure by Design.

  • Method of propulsion —The model doesn’t have a steam engine; it runs on electricity.
  • Choosing to allow or disallow concurrent and parallel access is often a balance between performance and consistency. If state always needs to be consistent and updates interleaved with read operations, then using a locking mechanism makes sense. But if access is mostly reads, then locking can result in unnecessary thread contention. For some reason, contention caused by concurrent access is often easier to reason about in code than contention caused by parallel access. For example, if a method is synchronized, as in listing 4.1, only one thread at a time is allowed to access the method, because the intrinsic lock of the method’s object must be acquired.2  All other threads that try to access the method concurrently must then wait until the lock is released—and this could cause thread contention.

    Listing 6.2 Constructor takes the mandatory attributes, methods the optional
    import org.apache.commons.lang3.Validate.*;
    
    public class Account {
        private AccountNumber number;
        private LegalPerson owner;
        private Percentage interest;
        private Money creditLimit;
        private AccountNumber fallbackAccount;
    
        public Account(AccountNumber number,
                        LegalPerson owner,
                        Percentage interest) {    #1  
            this.number = notNull(number);    #2  
            this.owner = notNull(owner);    #2  
            this.interest = notNull(interest);    #2  
        }
    
        protected Account() {}    #3  
    
        public AccountNumber number() { ... }    #4  
    
        public LegalPerson owner() { ... }
    
        public void changeInterest(
                        Percentage interest) {    #5  
            notNull(interest);    #6  
            this.interest = interest;
        }
    
        public Money creditlimit() { ... }
    
        public void changeCreditLimit(
                        Money creditLimit) {    #7  
            notNull(creditLimit);
            this.creditLimit = creditLimit;
        }
    
        public AccountNumber fallbackAccount() {
            return fallbackAccount;
        }
    
        public void changeFallbackAccount(AccountNumber fallbackAccount) {
            notNull(fallbackAccount);
            this.fallbackAccount = Validate.notNull(fallbackAccount);
        }
    
        public void clearFallbackAccount() {
            this.fallbackAccount = null;
        }
    }
    
    class AccountService {
        void openAccount() {
            AccountNumber number = ...
            LegalPerson accountowner = ...
            Percentage interest = ...
            Money limit = ...    #8  
            Account account =
                new Account(number,
                            accountowner,
                            interest);    #9  
            account.changeCreditLimit(limit);    #10  
            accountRepostitory.registerNew(account);
        }
    }
    
    #1   Takes all arguments needed to create a fully valid object
    #2   Checks that nothing tries to sneak in null arguments
    #3   Nonpublic constructor might be needed for persistence framework
    #4   Accessor method with a more domain-friendly name than one prefixed with get
    #5   It’s possible to change the interest rate even after the account is created.
    #6   The interest rate is mandatory even if it’s changed and can’t be null.
    #7   Domain-friendly name of method that changes the credit limit
    #8   Number, owner, interest, and limit are fetched from other services.
    #9   No risk of forgetting any mandatory data
    #10   Optional field (not in constructor) as separate method call